You are at home, you start kernel compiling or backup and after 10 minutes you have to go out. For all the day. You just don’t want to stop the process you started but you don’t want that your computer stay power-on useless. Well, you could start the process from shell and append a “& halt” command, but you didn’t. It’s ok. It happens to me few times, and so I decided to write down a script to keep close.
#!/bin/bash
PID=$(zenity --list --title "Wait AnD Execute" --text "Select the process you want to look for" --column "PID" --column "Command" $(ps -eo pid,comm|grep -v COMMAND|grep -v grep|grep -v ps))
CMD=$( zenity --entry --title "Wait AnD Execute" --text "Insert the command you like to execute when $PID terminates")
while [[ $(ps -p $PID -o comm=) != "" ]]; do
sleep 1
#useless message needed by zenity to make progress bar pulsate
echo "x"
done|zenity --title "Wait AnD Execute" --progress --pulsate --text "Waiting process $PID termination" --auto-close
$CMD
It’s really simple:
- start the script with the permission you need to execute the wanted command (if you want to shutdown the computer the script must be started by root)
- select from the list the process that the script must wait
- insert the command the script must execute when the selected process terminates (like “halt” or “playsound /usr/share/sounds/phone.wav”)
I hope can be usefull, power to the shell!