help for Restart script

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

help for Restart script

Postby gardenair » Fri Oct 10, 2008 10:19 am

I want to shoult down or restart my system at 4 am .Please write the script that should do the specified task.

thanks in advance for the help.
gardenair
gardenair
Havaldaar
 
Posts: 106
Joined: Tue Dec 28, 2004 10:07 pm

Postby lambda » Fri Oct 10, 2008 11:15 am

type

Code: Select all

echo poweroff | at 0400
if you want to execute multiple commands, put the commands in a file, one per line, and then type

Code: Select all

at -f /path/to/file 0400
read the man page for at.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby x2oxen » Fri Oct 10, 2008 5:24 pm

If you want to do it on daily basis you can add a cron job with shutdown command
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
x2oxen
Major General
 
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Website: http://usmanpk.com
WLM: x2oxen@hotmail.com
Yahoo Messenger: x2oxen
Location: Faisalabad

Postby gardenair » Sun Oct 12, 2008 2:31 pm

well what should be the complete script ? and after writing the script in a text editor should i place in /etc folder ? guide me.
gardenair
Havaldaar
 
Posts: 106
Joined: Tue Dec 28, 2004 10:07 pm

Postby eternal peace » Mon Oct 13, 2008 5:43 pm

There's no need to write a script for that as posted earlier you can do that using crontab only, here's how,

To add the cron job, do,
crontab -e

then, add,

0 4 * * * reboot
or
0 4 * * * poweroff

(to reboot or shutdown system at 4:00 a.m)

save changes and exit.
hail to linux!!!
eternal peace
Naik
 
Posts: 86
Joined: Thu Apr 03, 2003 6:44 pm

Postby gardenair » Wed Oct 15, 2008 1:33 pm

chmod +x /etc/cron.daily/sysshutdown


what about it? your suggestions?
gardenair
Havaldaar
 
Posts: 106
Joined: Tue Dec 28, 2004 10:07 pm

Postby x2oxen » Wed Oct 15, 2008 9:06 pm

no need to do that.. Just add a cronjob as advised earlier
Muhammad Usman

+92-321-6640501

Chemonics International

http://usmanpk.com
x2oxen
Major General
 
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Website: http://usmanpk.com
WLM: x2oxen@hotmail.com
Yahoo Messenger: x2oxen
Location: Faisalabad

Postby lambda » Thu Oct 16, 2008 11:46 am

all cron.daily scripts (on my system) run at 6:25am (see your /etc/crontab for details). you could change the time in /etc/crontab, but then some of the scripts in /etc/cron.daily will run, and the rest won't because your shutdown script ran first.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby nomankhn » Fri Oct 31, 2008 6:04 am

I think he is asking home work step by step.?

Thanks,
Noman Liaquat
nomankhn
Colonel
 
Posts: 714
Joined: Wed Aug 07, 2002 8:00 pm

Postby x2oxen » Fri Oct 31, 2008 9:44 am

Noman that was 15 days ago.. Come move on to new posts :D
Muhammad Usman

+92-321-6640501

Chemonics International

http://usmanpk.com
x2oxen
Major General
 
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Website: http://usmanpk.com
WLM: x2oxen@hotmail.com
Yahoo Messenger: x2oxen
Location: Faisalabad

Postby nomankhn » Sat Nov 01, 2008 4:57 am

x2oxen wrote:Noman that was 15 days ago.. Come move on to new posts :D


i got yesterday na :P

Thanks,
Noman Liaquat
nomankhn
Colonel
 
Posts: 714
Joined: Wed Aug 07, 2002 8:00 pm


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron