# cronjob Command for Shutdown

**URL:** <https://community.unix.com/t/cronjob-command-for-shutdown/301850>\
**Category:** Red Hat\
**Created:** [December 29, 2011, 1:10am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850 "2011-12-29T01:10:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![babinlonston](https://community.unix.com/user_avatar/community.unix.com/babinlonston/32/2460_2.png) [@babinlonston](https://community.unix.com/u/babinlonston)\
**Post date:** [December 29, 2011, 1:10am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/1 "2011-12-29T01:10:25Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![verdepollo](https://community.unix.com/user_avatar/community.unix.com/verdepollo/32/1854_2.png) [@verdepollo](https://community.unix.com/u/verdepollo)\
**Post date:** [December 29, 2011, 1:28am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/2 "2011-12-29T01:28:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![babinlonston](https://community.unix.com/user_avatar/community.unix.com/babinlonston/32/2460_2.png) [@babinlonston](https://community.unix.com/u/babinlonston)\
**Post date:** [December 29, 2011, 4:41am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/3 "2011-12-29T04:41:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![getrue](https://community.unix.com/letter_avatar/getrue/32/6_449c533f586939b6e5f246632a46421f.png) [@getrue](https://community.unix.com/u/getrue)\
**Post date:** [December 29, 2011, 5:18am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/4 "2011-12-29T05:18:31Z")

</div>

```nohighlight
#crontab -l // for listing

```

```nohighlight
#crontab -e // for editing

```

add below line

```nohighlight
5 18 * * * /usr/sbin/shutdown

```

or init 0

if crontab -e wouldn't work you must do

```nohighlight
/var/spool/cron/crontabs>vi root

```

or

```nohighlight
export EDITOR=vi

```

than you can edit crontab

---

<div class="post-metadata">

**Author:** ![admin\_xor](https://community.unix.com/user_avatar/community.unix.com/admin_xor/32/2337_2.png) [@admin\_xor](https://community.unix.com/u/admin_xor)\
**Post date:** [December 29, 2011, 7:22am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/5 "2011-12-29T07:22:10Z")

</div>

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

```nohighlight
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.

```nohighlight
# 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

```

---

<div class="post-metadata">

**Author:** ![babinlonston](https://community.unix.com/user_avatar/community.unix.com/babinlonston/32/2460_2.png) [@babinlonston](https://community.unix.com/u/babinlonston)\
**Post date:** [December 30, 2011, 1:24am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/6 "2011-12-30T01:24:03Z")

</div>

thank u mr.admin\_xor & getrue

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

> [@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).
> 
> ```plaintext
> 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.
> 
> ```plaintext
> # 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

---

<div class="post-metadata">

**Author:** ![admin\_xor](https://community.unix.com/user_avatar/community.unix.com/admin_xor/32/2337_2.png) [@admin\_xor](https://community.unix.com/u/admin_xor)\
**Post date:** [December 30, 2011, 2:30am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/7 "2011-12-30T02:30:43Z")

</div>

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.

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

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

```

---

<div class="post-metadata">

**Author:** ![babinlonston](https://community.unix.com/user_avatar/community.unix.com/babinlonston/32/2460_2.png) [@babinlonston](https://community.unix.com/u/babinlonston)\
**Post date:** [December 30, 2011, 4:26am UTC](https://community.unix.com/t/cronjob-command-for-shutdown/301850/8 "2011-12-30T04:26:58Z")

</div>

Thanks a lot lot
