Advertisement
metnix

start_at_exit.sh

Jun 21st, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script will wait for a given process to end and then run a given command.
  4. # Usage:
  5. #   start_at_exit.sh PNAME COMMAND
  6. #
  7. # Where:
  8. #   PNAME   name of the process we are waiting for to end (as displayed by ps)
  9. #   COMMAND the command that will be executed when no running process is detected anymore
  10.  
  11. PNAME=$1
  12. COMMAND=$2
  13.  
  14. if [ "$#" -ne 2 ]; then
  15.   echo "Number of arguments are $#, expected 2"
  16.   exit 10
  17. fi
  18.  
  19. echo "Waiting for all processes matching pattern '$PNAME' to finish..."
  20. while [ ! -z "$(ps -A|grep $PNAME)" ]; do
  21.   sleep 10;
  22. done
  23.  
  24. STR="No more processes detected after $SECONDS s, will now execute command:\n$COMMAND"
  25. echo -e $STR
  26. notify-send -u normal "start_at_exit.sh" "$STR"
  27.  
  28. exec $COMMAND
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement