If you use Fedora Core, or another system that uses “yum” to update packages, you can set it to run automatically every day / week / month (or even hour, if you’re crazy!) fairly easily. This is slightly different to the documentation on the Fedora website, this method is a bit more customisable.
Firstly, use su to gain root access to your system:
[phill@dibber ~]$ su -
Password:
[root@dibber ~]#
(Yes, dibber is the name of my machine. Just… don’t ask, OK?)
Secondly, create a file in /etc/cron.daily/ called ‘yum-update-all.cron’ (change ‘daily’ to be ‘weekly’ or ‘monthly’ if you like). You can use any editor you like, I prefer to use vi or vim:
[root@dibber ~]# vim /etc/cron.daily/yum-update-all.cron
Thirdly, insert something like the following into the file (explanation to follow):
#!/bin/sh
# Update everything
/usr/bin/yum -y update >> /home/phill/logs/yum-update-`date +%F_%H-%M`.log
chown phill:phill /home/phill/logs/*.* > /dev/null 2>&1
Explanation: /usr/bin/yum -y update
will execute the ‘update all’ command. >> /home/phill/logs/yum-update-`date +%F_%H-%M`.log
will redirect all output to the file /home/phill/logs/yum-update-(date).log. (substitute /home/phill/logs for a directory that exists where you want the log file to be output). Note the way you can include the output of another command there – surrounding it with two ` characters. To find out more about date formats type in: man date
at the command-line.
The second line (chown …) changes the ownership of all the files in the directory /home/phill/logs (whichever you specified in the previous line) back, as because the script runs as root it will get created with root permissions which you wouldn’t be able to read normally!
Lastly, the > /dev/null 2>&1
bit means that any output will get discarded (as opposed to the default, which is e-mailing any output to the user who runs the job).
Once you’ve edited the file and replaced all necessary bits with what you want, exit the editor, and then make the file executable:
[root@dibber ~]# chmod +x /etc/cron.daily/yum-update-all.cron
(if you did it weekly or monthly instead, change ‘daily’ to ‘monthly’ or ‘weekly’ – you know the score).
And… you’re done! The job should automatically run at about 4:00AM daily / weekly / monthly, depending. When it’s run successfully, you should see the log file in your log file directory that you specified.
Any questions, let me know!
Leave a Reply