Need script to automate update

Asked by chintalvaady

Hi,
I was wondering if its possible to write a shell script to automate the update process in my ubuntu 10.10 computer.The script should check following conditions before initiating update manger.

if
time <= 2.00 hrs (IST*) && >= 8:00 hrs (IST*)

run update manager

else

dont run

Description:
When the computer is switched on between 2 am to 8am,the computer should automatically perform update and should down automatically shut-down after finishing the update process.All these things should be done without any human interaction.(The minimum interaction would for a person to switch on a the PC).

Guys as i have no idea abt shell scripting,pls help me to write a script to perform above activities.

* IST- Indian standard time.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu cron Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
Last query:
Last reply:
Revision history for this message
mycae (mycae) said :
#1
Revision history for this message
mycae (mycae) said :
#2

oh the command you want to execute is :
 apt-get update && apt-get upgrade

you will need to install this as a task run by the root user.

Revision history for this message
chintalvaady (cmraghavendran) said :
#3

Thanks for the immediate reply.Can you pls help me by writing the script if possible.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#4

Just use cron. This is what I do:

run:

gksudo gedit /usr/bin/fullupdate; sudo chmod +x /usr/bin/fullupdate

add this text:

#!/bin/bash
clear
echo "Updating APT database..."
sudo apt-get update > /dev/null 2>&1
sudo apt-get -y dist-upgrade
sudo apt-get -y upgrade
sudo apt-get clean

Close gedit and run:

export EDITOR=nano; sudo crontab -e

Add this line:

2 0 * * * /usr/bin/fullupgrade

Press CTRL+X
Press Y
Press ENTER

This will make the script run as root at 2am every day!

Revision history for this message
chintalvaady (cmraghavendran) said :
#5

Thank you.,Script installed successfully.
Now a question.
Assuming that my system is not up & running 24/7,what happens if the computer is powered on at 2:15(Since the job is scheduled at 2:00)
and

do i need to login as admin for this update to happen??

Revision history for this message
Best actionparsnip (andrew-woodhead666) said :
#6

No the cron job will run in the background and do it's thing, there is no "admin" to log on as, all your users in Ubuntu are users.

If the time is missed, the command will not run. You could make another script which checks the time at boot and runs the script if it's needed. This will require you to authenticate it with your password.

Revision history for this message
chintalvaady (cmraghavendran) said :
#7

If that is the case,I think the script needs to be changed.Because there are very little possibility's that the comp will be switched on a 2am sharp.
Now is it possible to change the script to run any time between 2am to 8 am.

Revision history for this message
Ted C (tedc) said :
#8

Very simple doco re' crons here : http://www.scrounge.org/linux/cron.html

You could modify Actionparnip's script using this to say try to run the task every 10 minutes between the times you've asked for.

Revision history for this message
chintalvaady (cmraghavendran) said :
#9

Thanks Issue Resolved

Revision history for this message
chintalvaady (cmraghavendran) said :
#10

Thanks actionparsnip, that solved my question.