PDA

View Full Version : What command is needed for shuting down the system?



hovzio
April 22nd, 2008, 05:40 PM
Hi, I've been learning about shell scripts (More like I've been learning bash basics) lately and have started to (attempt to) write some of my own. So far its been going rather well and I'm having a a great deal of fun with it.

To my question. Example: So I have this script that runs for a few hours and I'd like to let it run overnight, is it possible to shutdown the computer from within a bash script?(at the end of it) What is the appropriate command to shutdown the pc? I am new to Ubuntu and Linux so it would be really nice if options and so forth are somewhat defined. I appreciate any help, input, ... on the subject.

lizzard
April 22nd, 2008, 05:45 PM
Either use "sudo shutdown now -h" or "sudo init 0" to shutdown your system.

teeceegee
April 22nd, 2008, 05:45 PM
Try shutdown.

Read the man page "man shutdown" for the options.

Cheers
TCG

hums07
April 22nd, 2008, 05:45 PM
http://www.mrhope.com/unix/ushutdow.htm
example to shutdown at 8 o'clock:
sudo shutdown 8:00

Elijah
April 22nd, 2008, 05:49 PM
I use 'halt' ;)

hovzio
April 22nd, 2008, 05:55 PM
Thanks! Is it possible to use these commands at the end of a shell script?

bobbocanfly
April 22nd, 2008, 06:02 PM
Yes you could put these at the end of a bash script but they would need to be run with root priveleges to work.

twright
April 23rd, 2008, 04:13 PM
or you could run sudo ./script && halt

tahnok
April 23rd, 2008, 04:28 PM
or ./script&&sudo halt if you don't want to give the script root permissions.

eriqjaffe
April 23rd, 2008, 05:33 PM
Yes you could put these at the end of a bash script but they would need to be run with root priveleges to work....you could also edit the sudoers file so that you can run shutdown -h without having to enter a password. There are plenty of threads about that around here.

stchman
April 23rd, 2008, 05:55 PM
Hi, I've been learning about shell scripts (More like I've been learning bash basics) lately and have started to (attempt to) write some of my own. So far its been going rather well and I'm having a a great deal of fun with it.

To my question. Example: So I have this script that runs for a few hours and I'd like to let it run overnight, is it possible to shutdown the computer from within a bash script?(at the end of it) What is the appropriate command to shutdown the pc? I am new to Ubuntu and Linux so it would be really nice if options and so forth are somewhat defined. I appreciate any help, input, ... on the subject.

I use:


sudo reboot

This command can be used in a shell script provided the script is being run as root.