Setting Up a Cronjob on Google Compute Engine

Setting up a cronjob on Google Compute Engine

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.

How to create a cron job on a Google Compute Engine instance via a PHP App Engine application?

Because your google cloud instances can go down or up at any minute, (And also, you may have multiple instances of the same app running), which would make cron unreliable as it may trigger multiple times across multiple machines, google has created Task Scheduling, which is available on Google Compute Engine.

A great tutorial can be found here, and a sample can be found here.

For a PHP specific implementation of pub/sub, see this link.

Schedule a Python script in crontab on Google Compute Engine VM

In Google Compute Engine, with an Ubuntu 16.04 VM, the user-level cron jobs don't seem to be kicked off at all; however, root-level jobs work as expected.

Instead of editing crontab like this:

crontab -e

use sudo crontab -e

A simple, working example is * * * * * /usr/bin/python /home/myUserName/test.py to run test.py once a minute.

Cronjob doesn't run on Google Compute Engine

The cron job is wrong because you need to use absolute paths in your command. Try:

/bin/bash /home/username/helloworld.sh

2019: Dynamic cron jobs Google App Engine

You may want to have a look at the new Google Cloud Scheduler service (in beta at the moment), which is a fully managed cron job service. It allows you to create cron jobs programmatically via its REST API. So you could create a specific cron job per customer with the appropriate schedule to fit you needs.



Related Topics



Leave a reply



Submit