Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to schedule the shell script using Google Cloud Shell?

I have a .sh file that is stored in GCS. I am trying to schedule the .sh file through google cloud shell.

I can run the same file using gsutil cat gs://miptestauto/baby.sh | sh command but not able to schedule it.

Following is my code for scheduling the file:

16 17 * * * gsutil cat gs://miptestauto/baby.sh | sh

It displays the message as "auto saving..done" but the scheduled job is not get displayed when I use crontab -l

# contents of .sh file 
bin/bash
bq load --source_format=CSV babynames.baby_destination13 gs://testauto/yob2010.txt name:string,gender:string,count:integer

Please can anyone tell me how schedule it using google cloud shell. I am not using compute engine/app engine. Just wanted to schedule it using the cloud shell.

thank you in advance :)

like image 875
samit Avatar asked Dec 04 '25 18:12

samit


1 Answers

As per the documentation, Cloud Shell is intended for interactive use only. The Cloud Shell instances are provisioned on a per-user, per-session basis and sessions are terminated after an hour of inactivity.

In order to schedule a daily cron job, the instance needs to be up and running all time but this doesn’t happen with Cloud Shell and I believe your jobs are not running because of this.

When you start Cloud Shell, it provisions a f1-micro instance which is the same machine type you can get for free if you are eligible for “Always Free”. Therefore you can create a f1-micro instance, configure the cron job on it and leave it running so it can execute the daily job.

You can check free usage limits at https://cloud.google.com/compute/pricing#freeusage

like image 80
JMD Avatar answered Dec 06 '25 14:12

JMD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!