From 814dc757db034e785e59579bdc6d2dddf0a75f07 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 16 Aug 2019 04:32:46 +0300 Subject: [PATCH] Attempt to mitigate script issues --- script/alivecheck | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/script/alivecheck b/script/alivecheck index 0d29ed7..6710f43 100755 --- a/script/alivecheck +++ b/script/alivecheck @@ -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