0

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?

Abhay
  • 827
  • 9
  • 34
  • Can you try: "sudo service cron reload" or "/etc/init.d/cron reload" command? – ARINDAM BANERJEE Jun 04 '20 at 08:35
  • I tried `sudo service cron relead` and it gave me this output `[ ok ] Reloading configuration files for periodic command scheduler: cron.` I'll check if the script runs in 10 mins – Abhay Jun 04 '20 at 08:37
  • The cronjob did not run, is there anything else that I can try? If it helps, my script is written in python 3 and it runs if I do a `python dataPull.py` – Abhay Jun 04 '20 at 08:51
  • Do you know if it has permission issue ? check the permission. Also verify if you need to add sudo. – ARINDAM BANERJEE Jun 04 '20 at 09:26

1 Answers1

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.

Wojtek_B
  • 4,245
  • 1
  • 7
  • 21