As a Linux system administrator, you get to patch (update) systems quite often. And sometimes, it may drive you insane as production servers are scheduled to update at unpleasant times, like midnight on the weekends, 04:00 AM, 02:00 AM, etc. It would be nice to automate such a hectic task and get more sleep, right?
Let's switch to the root user and then create a bash script named auto_patch.sh
in /root:
root@ubuntu-linux:~# cat auto_patch.sh
#!/bin/bash
apt-get -y update
apt-get -y upgrade
shutdown -r now
Notice that the script auto_patch.sh is tiny; only three lines. We have used the
-y option with the apt-get commands, which automatically answers Yes to all prompts during the system update; this is important because you will not be sitting in front of the computer while the script is running!
Now make the script executable:
root@ubuntu-linux:~# chmod +x auto_patch.sh
Finally, you need to schedule a cron job to run the auto_patch.sh script. Let's assume...