Attempt to mitigate script issues

This commit is contained in:
mathias 2019-08-16 04:32:46 +03:00
parent 16bd07d87e
commit 814dc757db

View file

@ -1,12 +1,21 @@
#!/bin/sh
while true; do
sleep 180
date="$(tail -1 $HOME/logs/latest.log | grep -oP '(?<=\[).*?(?=\])' | head -1 | date -f - +%s)"
if [ "$(env printf '\xFE' | nc -w 5 localhost 25565 | wc -m)" -eq 0 ] ||
[ "$(( $(date +%s) - ${date:=$(date +%s)} ))" -gt 180 ]; then
if [ "$(tail -20 $HOME/logs/latest.log | grep -c 'ERROR]: Requested chunk')" -eq 1 ]; then
rm -rf $HOME/worlds/
logfile=$HOME/logs/latest.log
if [ "$(env printf '\xFE' | nc -w 5 localhost 25565 | wc -m)" -eq 0 ]; then
if [ -f "$logfile" ]; then
if [ "$(tail -20 $logfile | grep -c 'ERROR]: Requested chunk')" -eq 1 ]; then
rm -rf $HOME/worlds/
fi
fi
pkill -9 java
elif [ -f "$logfile" ]; then
date="$(tail -1 $logfile | grep -oP '(?<=\[).*?(?=\])' | head -1 | date -f - +%s)"
if [ "$(( $(date +%s) - ${date:=$(date +%s)} ))" -gt 180 ]; then
if [ "$(tail -20 $logfile | grep -c 'ERROR]: Requested chunk')" -eq 1 ]; then
rm -rf $HOME/worlds/
fi
pkill -9 java
fi
fi
done