cron-update-lxcs.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. # bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/cron-update-lxcs.sh)"
  7. clear
  8. cat <<"EOF"
  9. ______ __ __ __ __ __ _ ________
  10. / ____/________ ____ / / / /___ ____/ /___ _/ /____ / / | |/ / ____/____
  11. / / / ___/ __ \/ __ \ / / / / __ \/ __ / __ `/ __/ _ \ / / | / / / ___/
  12. / /___/ / / /_/ / / / / / /_/ / /_/ / /_/ / /_/ / /_/ __/ / /___/ / /___(__ )
  13. \____/_/ \____/_/ /_/ \____/ .___/\__,_/\__,_/\__/\___/ /_____/_/|_\____/____/
  14. /_/
  15. EOF
  16. add() {
  17. while true; do
  18. read -p "This script will add a crontab schedule that updates all LXCs every Sunday at midnight. Proceed(y/n)?" yn
  19. case $yn in
  20. [Yy]*) break ;;
  21. [Nn]*) exit ;;
  22. *) echo "Please answer yes or no." ;;
  23. esac
  24. done
  25. sh -c '(crontab -l -u root 2>/dev/null; echo "0 0 * * 0 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/bash -c \"\$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh)\" >>/var/log/update-lxcs-cron.log 2>/dev/null") | crontab -u root -'
  26. clear
  27. echo -e "\n To view Cron Update LXCs logs: cat /var/log/update-lxcs-cron.log"
  28. }
  29. remove() {
  30. (crontab -l | grep -v "github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh") | crontab -
  31. rm -rf /var/log/update-lxcs-cron.log
  32. echo "Removed Crontab Schedule from Proxmox VE"
  33. }
  34. OPTIONS=(Add "Add Crontab Schedule"
  35. Remove "Remove Crontab Schedule")
  36. CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Cron Update LXCs" --menu "Select an option:" 10 58 2 \
  37. "${OPTIONS[@]}" 3>&1 1>&2 2>&3)
  38. case $CHOICE in
  39. "Add")
  40. add
  41. ;;
  42. "Remove")
  43. remove
  44. ;;
  45. *)
  46. echo "Exiting..."
  47. exit 0
  48. ;;
  49. esac