You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

02.AutoBackup_crontab_check.sh 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. Service1=/ED/Gitea_ED/Script_Gitea_ED/Gitea_EDbackup-mysql-Auto.sh
  3. Service2=/ED/Gitea_ED/Script_Gitea_ED/Gitea_EDbackup-Script_Gitea_ED-Auto.sh
  4. WHO=`whoami`
  5. crontab -u $WHO -l
  6. echo
  7. crontab -u $WHO -l | grep "$Service1" > /dev/null 2>&1
  8. if [[ $? == 0 ]]; then
  9. crontab -u $WHO -l | grep "$Service1" | cut -c 1-8 | grep "#"
  10. if [[ $? != 0 ]]; then
  11. echo -e "\033[33mPass. $Service1 is running. \033[0m"
  12. else
  13. echo -e "\033[41;37mFail. $Service1 was appended, but not be set as executing. \033[0m"
  14. echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
  15. echo -e "\033[33m#// Create backup file every 2 days at 02:08\033[0m"
  16. echo -e "\033[33m8 2 */2 * * $Service1\033[0m"
  17. fi
  18. else
  19. echo -e "\033[41;37mFail. $Service1 was not be set as executing. \033[0m"
  20. echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
  21. echo -e "\033[33m#// Create backup file every 2 days at 02:08\033[0m"
  22. echo -e "\033[33m8 2 */2 * * $Service1\033[0m"
  23. fi
  24. crontab -u $WHO -l | grep "$Service2" > /dev/null 2>&1
  25. if [[ $? == 0 ]]; then
  26. crontab -u $WHO -l | grep "$Service2" | cut -c 1-8 | grep "#"
  27. if [[ $? != 0 ]]; then
  28. echo -e "\033[33mPass. $Service2 was set active. \033[0m"
  29. else
  30. echo -e "\033[41;37mFail. $Service2 was appended, but not be set as executing. \033[0m"
  31. echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
  32. echo -e "\033[33m#// Create backup file every first day of month at 02:06"
  33. echo -e "\033[33m6 2 1 * * $Service2\033[0m"
  34. fi
  35. else
  36. echo -e "\033[41;37mFail. $Service2 was not be set as executing. \033[0m"
  37. echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
  38. echo -e "\033[33m#// Create backup file every first day of month at 02:06"
  39. echo -e "\033[33m6 2 1 * * $Service2\033[0m"
  40. fi
  41. echo