Josh Selfe
Josh Selfe

Reputation: 11

Running a script at scheduled times from Google Cloud VM (Ubuntu)

I am using the Google Cloud Platform to run a virtual Ubuntu Machine, and I would like to schedule a .sh script to run at 08:00 every day. I am currently using the free credit on the Google Cloud Platform, and would ideally keep it this way.

How could I schedule the VM to start-up, and the script to run every day?

Upvotes: 0

Views: 1294

Answers (2)

Serhii
Serhii

Reputation: 4461

At first, have a look at this article Save money by stopping and starting Compute Engine instances on schedule and then go to the documentation Scheduling compute instances with Cloud Scheduler to find how to use Cloud Scheduler and Cloud Functions to automatically start and stop Compute Engine instances on a regular schedule using resource labels.

After that, follow the official documentation Ubuntu Cron Howto and configure schedule for your sh script.

As a result, you can start your VM instance, run your script and then stop your VM instance to save some money.

Upvotes: 1

TheoNeUpKID
TheoNeUpKID

Reputation: 893

there are a number of diffrent methods you can use though, I suppose it would depend on the use case. assuming its a one-off script file use cronjobs

great resource for editing cronjobs https://crontab.guru/#0_8_1-31_*_* and scheduling bash script tutorial: https://www.golinuxcloud.com/create-schedule-cron-job-shell-script-linux/

  • one off or bashscript: try using cronjobs to schedule script executions.

  • Ubuntu Program or project you created: Supervised - like a program controller you can use it to manage specific programs.

  • IT Automation multi-clusters: Ansible is pretty popular though there are others great if you have multiple clusters or instance of your VM connected using ssh.

Upvotes: 1

Related Questions