Reputation: 410
I was wondering if there any way I can shut down a computer (or VM on google cloud platform) once a group of processes are all completed in command line (bash)
For example: I have five jobs running: Job_1, ..., Job_5. Each job might complete at different time, and I would like to shut down the computer once all jobs are completed.
===============Some update===============
The commands that I used just submit the works, and they finished immediately, the works will become multiple processes and running on the back. In this case, should I shutdown the computer based on the status of the processes?
Upvotes: 0
Views: 46
Reputation: 531175
Since there is a command to shut down a computer, it's very simple:
{ job1; job2; job3; job4; job5; }; shutdown -h now
I put jobs 1 through 5 inside a command group only to show that you can run arbitrary shell commands as a single group, and when that completes, shutdown
will run. Inside the command group, you don't have to run the 5 jobs sequentially; you can run some or all of them in parallel, and use the wait
built-in command to prevent the command group from exiting until all 5 jobs are complete.
Upvotes: 2