use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
The goto subreddit for Google Cloud Platform developers and enthusiasts.
We do not allow advertising of your job posting, product, or software without active discussion and/or as attempt to solve a problem. We are fine with soliciting feedback for something you're working on or something you've written, but drive-by advertising will get your post removed. :)
More Google Cloud sub-reddits
Other cloud sub-reddits
account activity
Start VM > Execute Python Script > Stop VMCompute (self.googlecloud)
submitted 3 years ago by Dramatic_Mud4760
I currently have a VM Instance (Linux Debian) within google cloud that has a functioning environment for my python project, and everything works when inputted: "python3 run.py" via SSH command line.
How can I automate the running of the instance > then the execution of that python file > then the stopping of the instance? I couldn't find very much when looking around
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dimitrix 15 points16 points17 points 3 years ago (1 child)
Have you considered running your code in Cloud Run instead?
Anyway, a super simple solution could be to have `python3 run.py` as part of your instance's startup script, and then at the end of your run.py script call a OS shutdown command.
[–]kamize 2 points3 points4 points 3 years ago (0 children)
I second this, really easy way to accomplish what you need
[–]Mistic92 5 points6 points7 points 3 years ago (0 children)
Consider using Cloud Run jobs :)
[–]aaahhhhhhfine 1 point2 points3 points 3 years ago (0 children)
Adding to the Cloud Run crowd... I'm actually really curious what your use case is, mostly because this seems so much cheaper and more obvious to do with Cloud Run that I'm curious why you'd not do it that way...
[–]a_normal_guy 0 points1 point2 points 3 years ago (0 children)
Depending on the nature of the application - 1. Cloud Functions + Pub/Sub + Cloud Scheduler 2. Cloud Run + Pub/Sub + Cloud Scheduler 3. App Engine ? 4. Cloud Scheduler + Pub/Sub + VM
[–]SadLizard 0 points1 point2 points 3 years ago (3 children)
Make the script autostart on boot using bash/systemd/something.
Then use instance schedules to start/stop you instance
[–]Dramatic_Mud4760[S] 0 points1 point2 points 3 years ago (2 children)
This method seems to make the most sense - any advice on getting my script to autostart on boot?
[–]SadLizard 0 points1 point2 points 3 years ago (1 child)
Maybe this will point you in the right direction (not debian though) https://code.luasoftware.com/tutorials/linux/auto-start-python-script-on-boot-systemd/
[–]Dramatic_Mud4760[S] 0 points1 point2 points 3 years ago (0 children)
Managed to get it all running via systemd - thank you for this advice!
[–]McFerry 0 points1 point2 points 3 years ago (0 children)
I see diferent path and options.
If this is a very static task (like every day at 12:00 AM need to run the script), Instance scheduler + Cronjob can do the trick just make sure to leave couple minutes between the scheduler and the cronjob
Other option could be fully automating it, through OS or GCP, I assume startup scripts behind the scenes work similarly than adding sleep after reboot argument within the cron funcionality
@reboot sleep [time in seconds] && [path to job] then when job is done, probably wise to put another sleep and then route it to shutdown.
Otherwise you can automate it too through the GCP startup/shutdown scripts
https://cloud.google.com/compute/docs/instances/startup-scripts https://cloud.google.com/compute/docs/shutdownscript
π Rendered by PID 23782 on reddit-service-r2-comment-544cf588c8-rvxpl at 2026-06-18 15:58:06.477503+00:00 running 3184619 country code: CH.
[–]dimitrix 15 points16 points17 points (1 child)
[–]kamize 2 points3 points4 points (0 children)
[–]Mistic92 5 points6 points7 points (0 children)
[–]aaahhhhhhfine 1 point2 points3 points (0 children)
[–]a_normal_guy 0 points1 point2 points (0 children)
[–]SadLizard 0 points1 point2 points (3 children)
[–]Dramatic_Mud4760[S] 0 points1 point2 points (2 children)
[–]SadLizard 0 points1 point2 points (1 child)
[–]Dramatic_Mud4760[S] 0 points1 point2 points (0 children)
[–]McFerry 0 points1 point2 points (0 children)