Dee
Dee

Reputation: 411

Shutdown not running in cron

I have a part of my script to automatically shutdown my Mac.

...  
print("Shutting down now")
time.sleep(3)       
shutdown_now = "echo {} | sudo -S /sbin/shutdown -h now".format(shutdown_info["password"])
subprocess.Popen(shutdown_now, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print("THIS SHOULD NOT DISPLAY")  

The script is run in cron. When I receive the cron mail.

...  
Shutting down now
THIS SHOULD NOT DISPLAY  
?  
At EOF

The script executes and finishes without even shutting down my Mac. Am I missing something to be added to my script?

Upvotes: 0

Views: 497

Answers (1)

Steve
Steve

Reputation: 19

I would just use cron to specify the execution of the command, not a script. This just simplifies the troubleshooting.

  1. sudo crontab -e
  2. 59 23 * * * root /usr/sbin/shutdown -h now

MM HH DD 00 WW Command

MM: minute
HH: hour
DD: day of the month
OO: month
WW: day of week
Command with full path

So above: as root, execute /usr/sbin/shutdown -h now every day of the week, every month at 11:59 PM.

Upvotes: 1

Related Questions