SHARE
TWEET

Untitled

a guest Oct 10th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. time=$1
  4.  
  5. # name of screen session
  6. MINECRAFT=minecraft
  7.  
  8. # warning intervall in minutes; must be greater than 5
  9. WARNING_INTERVALL=15
  10.  
  11. #location of start script
  12. START_SCRIPT=/home/minecraft/main/startServer.sh
  13.  
  14. msgServerMinutes() {
  15.     screen -S $MINECRAFT -X stuff "say Server will restart in $1 minutes. $(printf '\r')"
  16.     #echo "Server will restart in $1 minutes."
  17. }
  18.  
  19. msgServerSeconds() {
  20.     screen -S $MINECRAFT -X stuff "say Server will restart in $1 seconds. $(printf '\r')"
  21.     #echo "Server will restart in $1 seconds."
  22. }
  23.  
  24. countDown() {
  25.     msgServerSeconds 60
  26.     sleep 30s
  27.     msgServerSeconds 30
  28.     sleep 15s
  29.     local timer=15
  30.     while [[ $timer -gt 0 ]]; do
  31.         msgServerSeconds $timer
  32.         sleep 1s
  33.         let timer-=1
  34.     done
  35.  
  36.     #echo stop
  37.     screen -S $MINECRAFT -X stuff "stop $(printf '\r')"
  38.  
  39.     sleep 1m
  40.     #echo $START_SCRIPT
  41.     screen -S $MINECRAFT -X stuff "$START_SCRIPT $(printf '\r')"
  42. }
  43.  
  44.  
  45. if [[ $time -lt $WARNING_INTERVALL ]]
  46. then
  47.     msgServerMinutes $time
  48.     # wait until there are 5 minutes left
  49.     sleep $((($time-5)*60))
  50.     time=5
  51. fi
  52.  
  53. while [[ $time -ge $WARNING_INTERVALL ]]; do
  54.     msgServerMinutes $time
  55.    
  56.     if [[ $(($time-$WARNING_INTERVALL)) -ge 5 ]]
  57.     then
  58.         let time-=$WARNING_INTERVALL
  59.         sleep $(($WARNING_INTERVALL*60))
  60.     else
  61.         # wait until there are 5 minutes left
  62.         sleep $((($time-5)*60))
  63.         time=5
  64.     fi
  65. done
  66.  
  67. msgServerMinutes $time
  68. sleep 4m
  69. countDown
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top