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 ? :wall:

Yes, it is possible. Take a look at man crontab

no its not mentioned in man crontab tried a lot there is only help for commands to edit r view

#crontab -l    // for listing
#crontab -e  // for editing

add below line

5 18 * * * /usr/sbin/shutdown

or init 0

if crontab -e wouldn't work you must do

/var/spool/cron/crontabs>vi root

or

export EDITOR=vi

than you can edit crontab

1 Like

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).

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.

# 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
1 Like

thank u mr.admin_xor & getrue

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

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

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.

#!/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:

55 17 * * * '/root/initshut.sh >/dev/null 2>&1'
1 Like

Thanks a lot lot