Quantcast
Channel: DJRavine's Codebook » Linux
Viewing all articles
Browse latest Browse all 7

Fedora 17 – Automatic Yum Update Bash Script via Crontab

$
0
0

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.

which yum

Set the path to yum.

YUM=/path/to/yum

Set where you want your log to be saved.

LOG=/path/to/log/folder

And here is the complete script. yumupdate.sh

#!/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.

--------------------------------------------------------------------------------
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.

crontab -e

Now, add your new script to the crontab.

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.

*     *     *     *     *  /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.


Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles



Latest Images