0

I've made a script to update and upgrade at 12.15 every Friday and after both of these jobs have been completed shut down.

The updates work fine, however it does not shut down afterwards. I've tried to look it up and used the suggestions that I could find so far, but it doesn't seem to do anything, this is my script:

#crontab
#minute(s) hour(s) day(s) month(s) weekday(s) command(s)

15 12 * * 5 (/usr/bin/apt-get -y update; /usr/bin/apt-get -y upgrade; /usr/bin/touch /home/pi/cron_output.log;) 2>&1 >> /home/pi/cron_output.log; /sbin/shutdown -h now;

The /sbin/shutdown -h now; part appears to not be working and I have no clue on how to fix it

I'm running this on a raspberry pi.

  • What is the location of this crontab entry? If in /etc/crontab, you would need to specify a user (e.g. root) before the command. If it is in /var/spool/cron/crontabs/pi (the location if you edited it as the pi user via crontab -e), then the pi user might not have sufficient access to run /sbin/shutdown. On my Raspberry Pi, the pi user is prompted for credentials when running /sbin/shutdown. – cherdt Oct 7 '18 at 18:19
  • The crontab is stored in /var/spool/cron/crontabs/pi it might be the case that pi does not have sufficient privileges. So does that mean that I should create a new crontab with sudo crontab -e -u root? – Joeri Oct 7 '18 at 18:26
  • I tried it an that seems to be the problem, thank you – Joeri Oct 7 '18 at 18:30
  • Glad it worked! It might be easy to forget where the entry is if it's in root's crontab, although that certainly works. I would probably put it in the existing /etc/crontab or create a new file in /etc/cron.d. The only difference in format between those and a specific user's crontab is that the username needs to be specified, e.g. 15 12 * * 5 root command – cherdt Oct 7 '18 at 18:33
0

ANSWER GIVEN BY cherdt, I ONLY POST BECAUSE IT'S A COMMENT AND I WANT TO CLOSE THIS QUESTION

I messed up the privileges, it had to be run as root. Either use /usr/bin/sudo before commands or create crontab as root

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.