iwel's e-notes about his World
linux
Schedule shutdown
Apr 30th
Commands
at- Execute a task at a specific time. For example, shutdown computer, send birthday remainder etc. Useful to schedule one job at a time or a single future event.
cron – If you want to shutdown Linux box automatically everyday 8 pm then you need to use cron instead of at command (see below for examples). Useful to schedule recurring events or daily events such as backup data, or check system security etc.
at Command Examples
Let us see how to shutdow a Linux automatically at 8 pm, type the command at 8pm and press [enter] key, then type halt followed by enter key. To save your job press CTRL+D.
# at 8pm
Sample outputs:
at> halt
(Press CTRL+D)
Try out the following utilities:
atq – List the current at jobs pending.
atrm – Used to remove pending at jobs.
at command accept fairly complex time specifications, for example:
Run job at 6am on monday:
at 6am monday
Run job in 5 minutes time:
at now + 5 minutes
Run job at 4pm but 3 days later:
at 4pm + 3 days
Run job at 10am on 31st July:
at 10am Jul 31
See the file /usr/share/doc/at/timespec for complete time specifications and read man pages of at, atq, atrm. Make sure you have atd service running, if not start it using the following command:
# /etc/init.d/atd start
I personally wouldn’t schedule a shutdown if i was downloading a few tarballs and the system needed to be off when it was complete, unattended.
what if the speed decreases and it doesn’t finish in time?
Sure, you could expect it to take long and give it lots of time… But what if it gets done early, wouldn’t it be better if it shut down after it was complete, and not wait for the set time?
best to do something like this, chain commands. so you tell it to download the file and then when its done, shutdown.
wget http://somehwere.com/path/to/some.file && halt
note: it has to be double & signs. single one will cause both commands to execute at the same time. double causes it to wait for the first one to exit (clean exit or not) before continuing.
i personally would probably use more along the lines of
wget http://somehwere.com/path/to/some.file 2>/home/kai/wget.log && halt
so level 2 outputs (errors) are logged. if the file stopped downloading before it was done, i would then know why by reading the output of wget.log
scheduled shutdowns with at or cron are better for just having a system shutdown _nomatter what_ at said time. if you want your tasks to finish first, chain them.
Or if you want to schedule a shutdown in the next 24 hours:
shutdown -h time
e.g:
shutdown -h 06:45
Check linux distro version
Jun 17th
having to manage a few server and install services,i need to know what distribution of linux for each box i handle. So, to check linux distro version of my box i would run this in my shell :
cat /proc/version
as for example, the result is like this for ubuntu :
Linux version 2.6.27-14-generic (buildd@palmer) (gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12) ) #1 SMP Wed Apr 15 18:59:16 UTC 2009
as for centos would like this :
Linux version 2.6.18-53.1.14.el5 (mockbuild@builder6.centos.org) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Wed Mar 5 11:36:49 EST 2008
easy right ?