Today I finally got around to making a Fedora 17 Linux Bash Script to automate my yum updates. It’s been on my todo list for a few months since I migrated over to Fedora 17. This simple bash script will firstly update yum itself, then it will run a complete system update. Everything will be logged to a file for verification at a later date.
yumupdate.sh
This is a very simple script. Just find where your yum is located.
|
1 |
which yum |
Set the path to yum.
|
1 |
YUM=/path/to/yum |
Set where you want your log to be saved.
|
1 |
LOG=/path/to/log/folder |
And here is the complete script. yumupdate.sh
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/bin/bash
# This script comes with no warranty ...use at own risk
# Copyright (C) 2012 Adan Rehtla AKA DJRavine
# Link: http://www.nadasoft.net/2012/11/12/fedora-17-automatic-yum-update-bash-script-crontab/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# This script provides a complete yum update
YUM=/usr/bin/yum
LOG=/var/log
echo "--------------------------------------------------------------------------------" >> $LOG/yumupdate.log
echo "`date` - YUM UPDATE STARTED" >> $LOG/yumupdate.log
echo "`date` - *** CHECKING FOR YUM UPDATES ***" >> $LOG/yumupdate.log
$YUM -y update yum | awk '{x="'"`date`"'"; printf "%s - %s\n",x,$0 }' >> $LOG/yumupdate.log
echo "`date` - *** CHECKING FOR SYSTEM UPDATES ***" >> $LOG/yumupdate.log
$YUM -y update | awk '{x="'"`date`"'"; printf "%s - %s\n",x,$0 }' >> $LOG/yumupdate.log
echo "`date` - YUM UPDATE COMPLETED" >> $LOG/yumupdate.log |
yumupdate.log
After you run the script to make sure it runs correctly. Check the log file. Here is an example of my log file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
--------------------------------------------------------------------------------
Mon Nov 12 12:28:20 EST 2012 - YUM UPDATE STARTED
Mon Nov 12 12:28:20 EST 2012 - *** CHECKING FOR YUM UPDATES ***
Mon Nov 12 12:28:20 EST 2012 - Loaded plugins: fastestmirror, langpacks, presto, refresh-packagekit, tidy-cache
Mon Nov 12 12:28:20 EST 2012 - Loading mirror speeds from cached hostfile
Mon Nov 12 12:28:20 EST 2012 - * fedora: mirror.optus.net
Mon Nov 12 12:28:20 EST 2012 - * rpmfusion-free: mirror.transact.net.au
Mon Nov 12 12:28:20 EST 2012 - * rpmfusion-free-updates: mirror.transact.net.au
Mon Nov 12 12:28:20 EST 2012 - * rpmfusion-nonfree: ucmirror.canterbury.ac.nz
Mon Nov 12 12:28:20 EST 2012 - * rpmfusion-nonfree-updates: ucmirror.canterbury.ac.nz
Mon Nov 12 12:28:20 EST 2012 - * updates: mirror.optus.net
Mon Nov 12 12:28:20 EST 2012 - No Packages marked for Update
Mon Nov 12 12:28:22 EST 2012 - *** CHECKING FOR SYSTEM UPDATES ***
Mon Nov 12 12:28:22 EST 2012 - Loaded plugins: fastestmirror, langpacks, presto, refresh-packagekit, tidy-cache
Mon Nov 12 12:28:22 EST 2012 - Loading mirror speeds from cached hostfile
Mon Nov 12 12:28:22 EST 2012 - * fedora: mirror.optus.net
Mon Nov 12 12:28:22 EST 2012 - * rpmfusion-free: mirror.transact.net.au
Mon Nov 12 12:28:22 EST 2012 - * rpmfusion-free-updates: mirror.transact.net.au
Mon Nov 12 12:28:22 EST 2012 - * rpmfusion-nonfree: ucmirror.canterbury.ac.nz
Mon Nov 12 12:28:22 EST 2012 - * rpmfusion-nonfree-updates: ucmirror.canterbury.ac.nz
Mon Nov 12 12:28:22 EST 2012 - * updates: mirror.optus.net
Mon Nov 12 12:28:22 EST 2012 - No Packages marked for Update
Mon Nov 12 12:28:24 EST 2012 - YUM UPDATE COMPLETED |
How to Automate
Ok, now you have the script. Edit your crontab.
|
1 |
crontab -e |
Now, add your new script to the crontab.
|
1 |
0 20 * * * /home/djravine/Scripts/Yum-Update/yumupdate.sh |
The above code is the example code I use in my own crontab. You need to setup the path and script for your own setup. Use the below sytax to help you setup crontab.
|
1 2 3 4 5 6 7 8 |
* * * * * /path/to/command.sh
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59) |
And there you have it, an Automatic Yum Update Bash Script via Crontab, Easy.










Good post. I am facing a few of these issues as well.
.