Archive

HowTo: Wait for any process to finish on Bash

Well, here's a quick one.

Let's say you're creating a KVM/Qemu guest; using oz-install; and you're tired, 'cause it's 06:31 and you need some sleep.

You don't want to wait the 2k seconds it takes to do all the work so you want to setup a bash script that waits for the process and, then, shuts down your computer.

Here's how:

Procedure

# become root
su -

# wait for oz-install to end and poweroff
while pgrep oz-install &> /dev/null; do echo "it's running..."; sleep 5; done; poweroff