问题
I am new to setting up cronjobs and I'm trying to do it on a virtual machine in google compute engine. After a bit of research, I found this StackOverflow question: Running Python script at Regular intervals using Cron in Virtual Machine (Google Cloud Platform)
As per the answer, I managed to enter the crontab -e
edit mode and set up a test cronjob like 10 8 * * * /usr/bin/python /scripts/kite-data-pull/dataPull.py
. I also checked the system time, which was in UTC, and entered the time according to that.
The step I'm supposed to take, as per the answer, is to run sudo systemctl restart cron
which is throwing an error for me:
sudo systemctl restart cron
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Any suggestions on what I can do to set up this cronjob correctly?
回答1:
Edit a cron jobs with crontab -e
and inset a line:
* * * * * echo test123 > /your_homedir_path/file.log
That will write test123
every minute into file.log file.
Then do tail if
and wait a couple minutes. You should see test123
lines appearing in the file (and screen).
If it runs try running your python file but first make your .py file executable with "chmod +x script.py
"
Here you can find my reply to similar question.
来源:https://stackoverflow.com/questions/62190127/setting-up-a-cronjob-on-google-compute-engine