0

I currently have a script set to run every 6 hours (0000, 0600, 1200, 1800) that restarts a minecraft server running in a detached GNU screen.

I'd like to create a script that runs on the hour, that will show the remaining time to the next restart.

I.E.: After a restart, every hour the script will send the time remaining to the screen session, which will interpret and print it to the server.

Currently the hourly script looks like this, but I have a feeling i'll run into issues after 6PM:

HOUR=`echo $(($(date +%H) - 6))`
tleft=`echo $((12 % $HOUR))`
screen -X setenv remain "$tleft" 
screen -X readbuf $remain
screen -x minecraft -X eval 'stuff "say The Server will restart in $remain hours"\015'
screen -x minecraft -X eval 'stuff "save-all"\015'

Any help is appreciated, thanks

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Alex
  • 33
  • 6

1 Answers1

0

Not sure why I didn't think of this before, but a simple if statement solved my problem:

hour=`echo $(date +%I)`

if [[ $hour -lt 6  ]];
then
    tleft=$((6 - $hour))
else
    tleft=$((12 - $hour))
fi

screen -X setenv saystring "Server will restart in $tleft hour(s)"
screen -X readbuf $saystring
screen -x minecraft -X eval 'stuff "say $saystring"\015'
screen -x minecraft -X eval 'stuff "save-all"\015'
Alex
  • 33
  • 6