4

Well as far as I can tell, I'm doing everything I've been told.

The command "shutdown -P now" at the commandline does exactly what I want - immediately shut down the computer. But using that command as a cron job just never happens.

I just want it to shut down Monday through to Friday, at 8:30pm, and then again at 9:30pm and 10:30pm. So here's what I do;

I type "crontab -e", and I add this at the bottom of the file:

30 20,21,22 * * 1-5 shutdown -P now

I press CTRL+O to "save" it, and then CTRL+X to quit. I get the "crontab: installing new crontab" message at the prompt.

But come 8:30pm, no shutdown. Nor at 9:30p, or 10:30pm.


Edit: Working through the list provided here; CronJob not running

I'm stopped at "Test cron is working". I enter the command

* * * * * /bin/echo "cron works" >> /tmp/file

And I get the error

Apps: command not found

Searching for this error in Google doesn't turn up anything relevant.

Also, I was finally able to see (thanks to the link) where to get my message log output - I'm in Linux Mint (should have mentioned that), so I needed the Ubuntu way of finding the log output. The shutdown command appears to be run, and the only "error" message is "no MTA installed", which (from what I just read) is just for emailing the output. Otherwise there doesn't seem to be any obvious error message... can someone make any sense of this?

domarius@Domarius-LinuxMint ~ $ grep CRON /var/log/syslog
Aug  3 08:17:01 Domarius-LinuxMint CRON[3259]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 09:17:01 Domarius-LinuxMint CRON[3876]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 10:17:01 Domarius-LinuxMint CRON[4122]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 11:17:01 Domarius-LinuxMint CRON[4349]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 12:17:01 Domarius-LinuxMint CRON[4719]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 13:17:01 Domarius-LinuxMint CRON[5028]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 14:17:01 Domarius-LinuxMint CRON[5317]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 15:17:01 Domarius-LinuxMint CRON[5933]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 16:17:01 Domarius-LinuxMint CRON[7083]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 20:26:38 Domarius-LinuxMint cron[1089]: (CRON) INFO (pidfile fd = 3)
Aug  3 20:26:38 Domarius-LinuxMint cron[1089]: (CRON) INFO (Running @reboot jobs)
Aug  3 20:30:01 Domarius-LinuxMint CRON[2670]: (root) CMD (shutdown -P now "Shutting down...")
Aug  3 20:30:01 Domarius-LinuxMint CRON[2671]: (domarius) CMD (/sbin/shutdown -p now)
Aug  3 20:30:01 Domarius-LinuxMint CRON[2669]: (CRON) info (No MTA installed, discarding output)
Aug  3 20:30:01 Domarius-LinuxMint CRON[2668]: (CRON) info (No MTA installed, discarding output)
Aug  3 21:17:01 Domarius-LinuxMint CRON[3058]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  3 21:30:01 Domarius-LinuxMint CRON[3232]: (domarius) CMD (/sbin/shutdown -p now)
Aug  3 21:30:01 Domarius-LinuxMint CRON[3233]: (root) CMD (shutdown -P now "Shutting down...")
Aug  3 21:30:01 Domarius-LinuxMint CRON[3231]: (CRON) info (No MTA installed, discarding output)
Aug  3 21:30:01 Domarius-LinuxMint CRON[3230]: (CRON) info (No MTA installed, discarding output)
Aug  3 22:17:01 Domarius-LinuxMint CRON[3515]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Domarius
  • 413
  • 1
  • 3
  • 13

4 Answers4

2

After my question was unhelpfully downvoted with a link to a lot of things that didn't work, I got the help I needed on the Linux Mint forums - the secret was to edit crontab using the sudo command; "sudo crontab -e" That and other useful info is at this post. https://forums.linuxmint.com/viewtopic.php?f=47&t=275029&p=1507982#p1507982

Domarius
  • 413
  • 1
  • 3
  • 13
1

04/13/2021 update:

Running: Ubuntu 20

Steps I used to make cronjob turn the computer off M-F at 3:45PM

  1. $ sudo crontab -e
  2. 45 13 * * 1-5 sudo shutdown -h now
cronjob-e
  • 11
  • 1
0

Check your cron logs, usually in /var/log/cron. Most likely it will be a path issue, use this.

30 20,21,22 * * 1-5 /sbin/shutdown -P now
Logu
  • 904
  • 9
  • 15
  • Actually I currently am using /sbin/shutdown in my latest test since the post, still nothing. And a wierd thing; I have /var/log, but no "cron" file or folder exists within it, even if I view hidden files. I've posted some extra info in the comments on my original post. – Domarius Aug 02 '18 at 22:39
  • 1
    _(domarius) CMD (/sbin/shutdown -p now)_ You are doing shutdown as domarius. Is this user allowed to shutdown? If not combine with `sudo` . Ex: `/usr/bin/sudo /sbin/shutdown -p now` and make sure it works on the command line first – Logu Aug 06 '18 at 11:12
  • thanks for your help, but as stated, the command works on the command line just fine. But all's well - after my question was unhelpfully downvoted with a link to a lot of things that didn't work, I got the help I needed on the Linux Mint forums - the secret was to edit crontab using the sudo command; "sudo crontab -e" That and other useful info is at this post. https://forums.linuxmint.com/viewtopic.php?f=47&t=275029&p=1507982#p1507982 – Domarius Aug 28 '18 at 05:07
  • just wanted to give you credit for the correct answer, seems in my previous comment I didn't fully understand your solution, although specifying the paths isn't necessary. – Domarius Mar 26 '19 at 01:32
0

sudo vim /etc/crontab

daily 10:00PM shutdown desktop

00 22 * * * root /sbin/poweroff

Raish Khan
  • 71
  • 5