Wednesday, 28 February 2018

linux - Why does this script fail when run from cron, but works when run manually?


I have a relatively simple bash script that works great when invoked directly, but fails when run by cron. Why does this fail and how can I make it work via cron?


#!/bin/bash
apt-get update -y
apt-get upgrade -y
apt-get install boinc-client -y

Once cron has attempted to run it, a manual invocation will result in this error:


dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.


But as long as it is executed the first time manually, it works just fine.



Answer



Managed to solve it with barely any understanding of what was going on. Turned out that even though I was running from root crontab, the apt-get commands still needed a sudo in front of them. Logically I had expected that not to be needed since the script was already executing "as root", but once I added sudo... everything worked exactly as expected.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...