0

I'm trying to get crontab to automatically schedule an update via "sudo apt-get update". I have also written a script that if I run it through Terminal (/home/pi/bin/update), it runs the update script but if I schedule crontab to run the update script, nothing. I also added the command "0 05 * * * sudo apt-get update" (run update at 05:00 every morning) into crontab and nothing either. If the update is running I don't see the update running in Terminal or even know if the command has run. What could I be missing?

2
  • Do you need to enter a password for user pi when running sudo? Why not run apt-get update directly as root?
    – user236012
    Commented Nov 14, 2017 at 10:46
  • You will not see any terminal output when cron runs a job. The script is running in its cron's shell, not yours. Redirecting the output to a file like CoderMike suggests below will enable you to see what's happening.
    – 88weighed
    Commented Jun 22, 2018 at 9:02

1 Answer 1

2

Check the log file to see if your cron command was executed:

grep CRON /var/log/syslog

Direct the output to a file to see the result of the command:

(test every minute)

*/1 * * * * sudo apt-get update > /home/pi/log.txt

(05:00 every day)

0 5 * * * sudo apt-get update > /home/pi/log.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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