2023-08-22 14:52:29 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Script: setup_auto_updates.sh
|
|
|
|
|
# Description: Script to set up automatic system updates using cron
|
|
|
|
|
|
|
|
|
|
# Update package lists and install cron
|
2023-01-29 18:14:14 -06:00
|
|
|
sudo apt update
|
2023-08-22 14:52:29 -05:00
|
|
|
sudo apt install cron -y
|
|
|
|
|
|
|
|
|
|
# Enable and start the cron service
|
2023-01-29 18:14:14 -06:00
|
|
|
sudo systemctl enable cron
|
2023-08-22 14:52:29 -05:00
|
|
|
sudo systemctl start cron
|
|
|
|
|
|
|
|
|
|
# Stop the cron service to make changes
|
2023-01-29 18:14:14 -06:00
|
|
|
sudo systemctl stop cron
|
|
|
|
|
|
2023-08-22 14:52:29 -05:00
|
|
|
# Add the update and upgrade cron job to /etc/cron.d/
|
2023-09-06 14:12:32 -05:00
|
|
|
# Old line that doesnt work
|
|
|
|
|
# echo 'MAILTO="alerts@tyates.one"
|
|
|
|
|
# 0 */6 * * * root apt-get update && apt-get -y -d full-upgrade && apt-get autoremove -y && sudo apt-get clean -y && sudo apt-get purge -y' | sudo tee /etc/cron.d/auto_updates
|
|
|
|
|
|
|
|
|
|
# Added new line to test.
|
2023-09-06 14:18:01 -05:00
|
|
|
echo '"MAILTO="alerts@tyates.one"
|
|
|
|
|
0 */6 * * * root apt-get update && apt-get -y -d full-upgrade && apt-get autoremove -y && sudo apt-get clean -y && sudo apt-get purge -y' | sudo tee -a /etc/crontab
|
2023-09-06 14:12:32 -05:00
|
|
|
|
2023-01-29 18:14:14 -06:00
|
|
|
|
2023-08-22 14:52:29 -05:00
|
|
|
# Restart the cron service to apply the new cron job
|
|
|
|
|
sudo systemctl start cron
|