Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #!/bin/bash
  2. #=======================================================#
  3. #   ToDo:                                               #                      
  4. #   - Add a set number on how many backups              #
  5. #     should be made.                                   #
  6. #=======================================================#
  7.  
  8.  
  9. GameType="Sandbox"              #Sandbox, Survival, Multiplayer, etc.
  10. SaveName="07-01-2017_04-52-11"  #Make sure you copy the folder name.
  11. Timeout=20                      #Timeout in seconds. The default of 300 (5 minutes) is likely adequate. Even numbers recommended.      
  12. SERVICE=ProjectZomboid64        #Change this to ProjectZomboid32 if you're using 32bit java!
  13. BackupCount=5                   #Amount of backups to be made.
  14. #===========================================================================================#
  15. #                               No need to change anything below.                           #
  16. #===========================================================================================#
  17. GameName="Project Zomboid"
  18. sleep 1 #Unused in final script
  19. #steam steam://rungameid/108600
  20. mkdir -p "$HOME/Zomboid/Saves/Backups/$SaveName"
  21. i=1
  22. Wait=$(($Timeout))
  23. while [ $i -gt -1 ]; do
  24.     while [ $Wait -gt 0 ]; do
  25.     clear && echo -ne "Creating a backup in" $Wait "seconds." && sleep 1
  26.     : $((Wait--))
  27.     done
  28.     if ps ax | grep -v grep | grep $SERVICE > /dev/null
  29.         then
  30.             cp "$HOME/Zomboid/Saves/$GameType/$SaveName/map_p.bin" "$HOME/Zomboid/Saves/Backups/$SaveName/map_p.bin.backup$i"
  31.             #Make $i +1 each time it passes through, until it reaches $BackupCount and resets to 1.
  32.             [ $i = 1 ] && i=2 || i=1
  33.             Wait=$(($Timeout))
  34.         else
  35.             Wait=$((30))
  36.             while [ $Wait -gt 0 ]; do
  37.                 clear && printf "$GameName is not detected as running, and no further backups will be made. \n"
  38.                 echo -ne "Checking if game is running in" $Wait "seconds." && sleep 1
  39.                 : $((Wait--))
  40.                 done
  41.                 if ps ax | grep -v grep | grep $SERVICE > /dev/null
  42.                     then
  43.                         Wait=$(($Timeout-30)) && continue          
  44.                 fi
  45.     fi
  46. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement