cronjob Command for Shutdown


 
Thread Tools Search this Thread
Operating Systems Linux Red Hat cronjob Command for Shutdown
# 1  
Old 12-29-2011
Debian cronjob Command for Shutdown

Hi Guys Pls give me cronjob command for Network pcs to be shutDown on 06:05 PM is it possible to do in cronjob ? Smilie
# 2  
Old 12-29-2011
Yes, it is possible. Take a look at man crontab
# 3  
Old 12-29-2011
no its not mentioned in man crontab tried a lot there is only help for commands to edit r view
# 4  
Old 12-29-2011
Code:
#crontab -l    // for listing

Code:
#crontab -e  // for editing

add below line
Code:
5 18 * * * /usr/sbin/shutdown

or init 0

if crontab -e wouldn't work you must do
Code:
/var/spool/cron/crontabs>vi root

or
Code:
export EDITOR=vi

than you can edit crontab
This User Gave Thanks to getrue For This Post:
# 5  
Old 12-29-2011
You can run a con job from a central machine to shutdown other machine using ssh. You need to configure ssh key sharing though for this to be working.

The below crontab entry will shutdown every machine specified in a file called /root/machines at 12 o'clock at night everyday (considering you are using Linux machines; syntax for shutting down other UNIX machines varies widely).
Code:
0 0 * * * '/bin/cat /root/machines | while read sys; do /usr/bin/ssh root@$sys "/sbin/shutdown -h now" 1>/dev/null 2>&1'

I assume you are already familiar with cron and how to schedule job with it. Below is the format for crontab entries. For detailed info, check the man page.

Code:
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

This User Gave Thanks to admin_xor For This Post:
# 6  
Old 12-30-2011
MySQL

thank u mr.admin_xor & getrue

---------- Post updated at 11:54 AM ---------- Previous update was at 10:36 AM ----------

Quote:
Originally Posted by admin_xor
You can run a con job from a central machine to shutdown other machine using ssh. You need to configure ssh key sharing though for this to be working.

The below crontab entry will shutdown every machine specified in a file called /root/machines at 12 o'clock at night everyday (considering you are using Linux machines; syntax for shutting down other UNIX machines varies widely).
Code:
0 0 * * * '/bin/cat /root/machines | while read sys; do /usr/bin/ssh root@$sys "/sbin/shutdown -h now" 1>/dev/null 2>&1'

I assume you are already familiar with cron and how to schedule job with it. Below is the format for crontab entries. For detailed info, check the man page.

Code:
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

ya now i have checked the shutdown command its working fine , But im having Centos as my server and there r 50 Pcs with ubuntu , I want to shutdown all 50 Pcs @ 06:05 PM But it need warning message @ 5:55 PM is it possible how can i set the command pls help me
# 7  
Old 12-30-2011
You can run the cron job at 5:55 PM with the following modifications. It's better if you could save the script in a file and make it executable and run it in cron.
Code:
#!/bin/bash

# initshut.sh file
/bin/cat /root/machines | while read sys; do
   # let's put it in the background and move on to the next machine
   ( /usr/bin/ssh root@$sys '/sbin/shutdown -h +10 "The system is going down after 10 minutes. Please save your work and log off before that. --Admin"' ) &
done

Please note the single and double quotes. Without their proper usage, the command will not be executed.

Then, make a crontab entry like this:
Code:
55 17 * * * '/root/initshut.sh >/dev/null 2>&1'


Last edited by admin_xor; 12-30-2011 at 03:40 AM..
This User Gave Thanks to admin_xor For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with shutdown command in script (MacOS High Sierra)

Hello, I have a backup script that runs an rsync backup to an external drive. I use the script frequently on Windows and Linux and have installed it on a Mac. The script has an option to run shutdown after the backup has completed. Since backup can take hours to run, this is an option that is... (10 Replies)
Discussion started by: LMHmedchem
10 Replies

2. UNIX for Dummies Questions & Answers

Top Command Output is not coming via Cronjob

Dear All, I created a small script to get the CPU, GIS usage etc automatically. However when i run this script manually its working , but when i run through cronjob i am not getting any output. Can anyone please help me on this. I am using SuseLinux. Thank you in advance. #!/bin/sh {... (2 Replies)
Discussion started by: Nitin Kapoor
2 Replies

3. Shell Programming and Scripting

Exit script when shutdown or reboot command is given

This is probably a simple question, but I'm new with writing scripts for Linux (IPFire in this case) and Google wasn't helpful with this. When creating a script, what is the best and/or proper way to have it exit automatically if the reboot or shutdown command is given? If that's even... (2 Replies)
Discussion started by: bartgrefte
2 Replies

4. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

5. AIX

Shutdown command

Hi, is there a difference between shutdown -Fand shutdown -h now? (3 Replies)
Discussion started by: x_adm
3 Replies

6. OS X (Apple)

Problems using shutdown -u command

I have a smart-ups connected to my OS X Snow Leopard server ver. 10.6. Based on the docs and forums I read, I have been trying to use the software provided by APC, PCNS. I have also tried to just use the UPS communications cable provided and use the OS' "UPS options". Neither of them work exactly... (1 Reply)
Discussion started by: mckorn99
1 Replies

7. UNIX for Dummies Questions & Answers

Script to force Oracle database shutdown when shutdown immediate does not work

I have Oracle 9i R2 on AIX 5.2. My Database is running in shared server mode (MTS). Sometimes when I shutdown the database it shutsdown cleanly in 4-5 mints and sometimes it takes good 15-20 minutes and then I get some ora-600 errors and only way to shutdown is by opening another session and... (7 Replies)
Discussion started by: aixhp
7 Replies

8. AIX

shutdown command

Hi, After issuing shutdown -F or shutdown -F now my server is getting restarted. Any Idea? (3 Replies)
Discussion started by: manoj.solaris
3 Replies

9. Shell Programming and Scripting

Need a cronjob command

Dear Exerts, I want to schedule a script which could run after every 35 minutes. please find below the command but it is not woring and running after every 35 minutes. 35 * * * * /opt/home/backup/test_dir/abc.sh > /opt/home/backup/test_dir/abc_cronlog.txt Please tell me what is the problem... (7 Replies)
Discussion started by: shary
7 Replies

10. Solaris

shutdown question from command line

solaris 10 logged in as root to command line...want to shut the system down....could not do this....when i chose shutdown the system seemed to squawk at me saying i'd lose whatever i was working on would be lost unless i logged out...after proceeding through this it took me to the gui log in... (6 Replies)
Discussion started by: drisnya
6 Replies
Login or Register to Ask a Question