ProxmoxVE-HelperScripts/misc/cron-update-lxcs.sh

57 lines
1.8 KiB
Bash
Raw Normal View History

2023-07-17 21:09:55 -04:00
#!/usr/bin/env bash
2024-01-01 12:13:05 -05:00
# Copyright (c) 2021-2024 tteck
2023-07-17 21:09:55 -04:00
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
2023-07-18 04:38:50 -04:00
# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/cron-update-lxcs.sh)"
2023-07-17 21:09:55 -04:00
clear
cat <<"EOF"
2023-07-18 04:38:50 -04:00
______ __ __ __ __ __ _ ________
/ ____/________ ____ / / / /___ ____/ /___ _/ /____ / / | |/ / ____/____
/ / / ___/ __ \/ __ \ / / / / __ \/ __ / __ `/ __/ _ \ / / | / / / ___/
/ /___/ / / /_/ / / / / / /_/ / /_/ / /_/ / /_/ / /_/ __/ / /___/ / /___(__ )
\____/_/ \____/_/ /_/ \____/ .___/\__,_/\__,_/\__/\___/ /_____/_/|_\____/____/
/_/
2023-07-17 21:09:55 -04:00
EOF
add() {
2023-07-18 04:38:50 -04:00
while true; do
read -p "This script will add a crontab schedule that updates all LXCs every Sunday at midnight. Proceed(y/n)?" yn
case $yn in
[Yy]*) break ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no." ;;
esac
done
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 -'
clear
echo -e "\n To view Cron Update LXCs logs: cat /var/log/update-lxcs-cron.log"
2023-07-17 21:09:55 -04:00
}
remove() {
(crontab -l | grep -v "github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh") | crontab -
2023-07-18 04:54:43 -04:00
rm -rf /var/log/update-lxcs-cron.log
2023-07-18 04:38:50 -04:00
echo "Removed Crontab Schedule from Proxmox VE"
2023-07-17 21:09:55 -04:00
}
2023-07-18 04:38:50 -04:00
OPTIONS=(Add "Add Crontab Schedule"
Remove "Remove Crontab Schedule")
2023-07-17 21:09:55 -04:00
2023-09-09 05:13:17 -04:00
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Cron Update LXCs" --menu "Select an option:" 10 58 2 \
2023-07-18 04:38:50 -04:00
"${OPTIONS[@]}" 3>&1 1>&2 2>&3)
2023-07-17 21:09:55 -04:00
case $CHOICE in
2023-07-18 04:38:50 -04:00
"Add")
add
;;
"Remove")
remove
;;
*)
echo "Exiting..."
exit 0
;;
2023-07-17 21:09:55 -04:00
esac