Advertisement
applehelpwriter

release open file (OS X)

May 11th, 2016
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #! /bin/bash
  2. # This script will list all open processes for the given file and give you an option to quit them.
  3. declare -a PROCS
  4.  
  5.  
  6. s=$(fuser -f "$1")
  7. PROCS=( $s )
  8. if [ "${#PROCS[@]}" == 0 ] ; then
  9.     echo "File is not open."
  10. else
  11.     for element in "${PROCS[@]}"
  12.     do
  13.         ps "$element"
  14.     done
  15.  
  16.     echo ""
  17.     read -p "Type the PID number to kill a given process, 'a' to kill all or 'q' to quit: "
  18.  
  19.     if [ "$REPLY" == "a" ] || [ "$REPLY" == "A" ] ; then
  20.         for element in "${PROCS[@]}"
  21.         do
  22.          kill "$element" || exit 1;
  23.         done
  24.         echo "Done"
  25.     elif [ "$REPLY" == "q" ] || [ "$REPLY" == "Q" ]; then
  26.         echo "User cancelled!"
  27.         exit 0;
  28.     else
  29.         kill "$REPLY" || exit 1
  30.     fi
  31. fi
  32.  
  33. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement