Cron
Install
On Linux (Compute Engine)
https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-ubuntu-1804
Open a terminal window and enter each command individually, press enter after each.
sudo apt update
sudo apt install cron
sudo systemctl enable cron
Time Zone
The time zone of your VM needs to be changed to ensure that the cron jobs are exectuted at the correct local time.
From this page, go root user
sudo -s
and use
dpkg-reconfigure tzdata
This will bring up a GUI which will guide you to change your timezone information
Afterwards, confirm the date/time by typing date. I am not sure if needed but the Compute Engine Region & Zone was changed to one in the same local time zone and the VM was restarted. This is from the Settings section for the VM in Compute Engine.
Script Files
Create .sh file
Create a file to contain the GAM command. Nano (https://www.nano-editor.org/) is a builtin text editor, so the terminal screen will change.
sudo nano <File Name>.sh
Then add
#! /bin/bash
/path/to/GAM/folder/<Your GAM Command Here>
Example
#! /bin/bash
/home/user_name/bin/gamadv-xtd3/gam crosqueries "status:active" print cros todrive
The commands in nano to save the file are
CTRL + x (to exit the file) > Y (to confirm saving the changes) > Enter (to confirm file name)
Make Executable
sudo chmod +x <File Name>.sh
Test
Make sure the script file is working.
./<File Name>.sh
Cron
Edit
Edit the file that controls all the cron jobs
crontab -e
Add
For example to run nightly at 1am. The /path/to/script/ is where the .sh file is stored, not the GAM location.
0 1 * * * /path/to/script/<File Name>.sh
Or, to run on the 4th day of every month. This example will run the script at 3.45am on the 4th day of every month.
45 3 4 * * /path/to/script/<File Name>.sh
Example
0 1 * * * * /home/user_name/scripts/update.sh
This website, https://crontab.guru/, has useful examples and an expression checker for creating the cron timing.
Backup
crontab -l > /path/to/backup/crontab.bak
Resources
https://futurestud.io/tutorials/ubuntu-debian-how-to-test-a-cron-job
https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-ubuntu-1804
https://www.geeksforgeeks.org/crontab-in-linux-with-examples/
https://tecadmin.net/crontab-in-linux-with-20-examples-of-cron-schedule/
https://cronitor.io/cron-reference
Time Zone - Compute Engine
linux > date to show day/time