cron-update-lxcs.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. clear
  7. cat <<"EOF"
  8. __ __ __ __ __ _ ________ ______
  9. / / / /___ ____/ /___ _/ /____ / / | |/ / ____/____ / ____/________ ____
  10. / / / / __ \/ __ / __ `/ __/ _ \ / / | / / / ___/ / / / ___/ __ \/ __ \
  11. / /_/ / /_/ / /_/ / /_/ / /_/ __/ / /___/ / /___(__ ) / /___/ / / /_/ / / / /
  12. \____/ .___/\__,_/\__,_/\__/\___/ /_____/_/|_\____/____/ \____/_/ \____/_/ /_/
  13. /_/
  14. EOF
  15. add() {
  16. while true; do
  17. read -p "This script will add a cron job to update all LXCs at midnight. Proceed(y/n)?" yn
  18. case $yn in
  19. [Yy]*) break ;;
  20. [Nn]*) exit ;;
  21. *) echo "Please answer yes or no." ;;
  22. esac
  23. done
  24. sh -c '(crontab -l -u root 2>/dev/null; echo "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 -'
  25. clear
  26. echo -e "\n To view Update LXCs Cron logs: cat /var/log/update-lxcs-cron.log"
  27. }
  28. remove() {
  29. (crontab -l | grep -v "github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh") | crontab -
  30. rm /var/log/update-lxcs-cron.log
  31. echo "Removed Update LXCs Cron from Proxmox VE"
  32. }
  33. # Define options for the whiptail menu
  34. OPTIONS=(Add "Add Update LXCs Cron to Proxmox VE" \
  35. Remove "Remove Update LXCs Cron from Proxmox VE")
  36. # Show the whiptail menu and save the user's choice
  37. CHOICE=$(whiptail --title "Update LXCs Cron for Proxmox VE" --menu "Select an option:" 10 58 2 \
  38. "${OPTIONS[@]}" 3>&1 1>&2 2>&3)
  39. # Check the user's choice and perform the corresponding action
  40. case $CHOICE in
  41. "Add")
  42. add
  43. ;;
  44. "Remove")
  45. remove
  46. ;;
  47. *)
  48. echo "Exiting..."
  49. exit 0
  50. ;;
  51. esac