I have a python that creates a cron job in order to call another python script, but it's not working properly.
In the first python I have:
from crontab import CronTabcron = CronTab(user=True)job = cron.new(command='/usr/bin/python3 /home/ubuntu/dev/alarm.py')job.minute.every(1)cron.write()
When I execute sudo crontab -u www-data -e
I can see it as:
* * * * * /usr/bin/python3 /home/ubuntu/dev/alarm.py
But it's not executing this alarm.py
script. If I try to execute the alarm.py
script as www-data
user I get error to import modules, because they were installed as user ubuntu
.
I.E.:
$ sudo -u www-data /usr/bin/python3 /home/ubuntu/dev/alarm.pyTraceback (most recent call last): File "/home/ubuntu/dev/alarm.py", line 1, in <module> from pushover import PushoverModuleNotFoundError: No module named 'pushover'
So I manually changed the www-data crontab
to:
* * * * * ubuntu /usr/bin/python3 /home/ubuntu/dev/alarm.py
In order to execute as ubuntu
user. But still not working.
Anything wrong here?
thanks.