Setting up a cron job to update Ubuntu machine

I wanted to use the cron system to update an Ubuntu machine everyday and send me emails with the results.

In order for the Ubuntu machine to send email from the cron job it needs to have the email in the command line set up see this post

We decided to write a shell script to do the job and then have it called by the cron job. This is an example of the script ( the -y option answers yes to questions that would be asked) You must make sure that the script is excecutable ie type “chmod 755 script.sh”

#!/bin/bash
proxy=http://proxy.url.com:8080
export http_proxy=$proxy
apt-get -y update
apt-get -y upgrade
updatedb

We are using the crontab that belongs to root (to access this “su” and then “crontab -e”) as the update commands must be performed as root.

Below is an example of our cron job, not you can send the results of the job to more than one person if you seperate each email address with a comma

MAILTO=me@here.com.au, you@there.com.au
# m h dom mon dow command
01 01 * * * /path/to/shell/script.sh
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s