So, I have this script that needs to run every minute, so I set up a cronjob to run the script, lets say the command is:
I use Webmin to setup the cronjob and set it to execute as www-data. I also use it to see the output when running the command.
When I execute the cronjob I get a permission error, when trying to create a file. But when I run the following command it works.
sudo -u www-data /var/www/script.py
Can anyone tell me why?
The file it is trying to create is called
runnning.txt and is placed next to the script (
The error the command generates when running as a cronjob
Traceback (most recent call last): File "/var/www/lager-scanner/filer/pluk_script.py", line 237, in <module> with open(filename, "w+") as f: PermissionError: [Errno 13] Permission denied: 'running.txt'
The contents of
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) #
sudo -u www-data crontab -l
# * * * * * /var/www/script.py
I don't know how webmin does its thing. It's a webinterface, where I just select what user the command is supposed to be run by.