fant0men

Pause HandBrake script

Sep 28th, 2019
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # This script finds a running HandBrake process, if it exists, and
  3. # pauses it. The user can resume the process later by typing
  4. # 'kill -s 18 $pid'.
  5. # The script runs 'kill -s 20 $pid', to suspend the process.
  6. # 20 = SIGSTP (kill -l)
  7.  
  8. pid_list_f='/dev/shm/handbrake_pid.txt'
  9. touch "$pid_list_f"
  10.  
  11. comm='HandBrakeCLI'
  12.  
  13. mapfile -t pids < <(ps -C "$comm" -o comm,pid | tail -n +2)
  14.  
  15. IFS="$IFS_bak"
  16.  
  17. for (( i = 0; i < ${#pids[@]}; i++ )); do
  18.  
  19.     mapfile -d' ' -t pid_info < <(sed 's/ \+/ /' <<<"${pids[${i}]}")
  20.     name=$(tr -d '[:blank:]' <<<"${pid_info[0]}")
  21.     pid=$(tr -d '[:blank:]' <<<"${pid_info[1]}")
  22.  
  23.     if [[ $name == $comm ]]; then
  24.         echo -e "\nSTOPPING!"
  25.         echo "NAME: ${name} : PID: ${pid}"
  26.         kill -s 20 "${pid}"
  27.  
  28.         echo "$pid" >> "$pid_list_f"
  29.        
  30.         # 18 = SIGCONT (kill -l)
  31.         echo -e "\nRun this command later to resume:"
  32.         echo -e "start_handbrake.sh\n"
  33.     fi
  34. done
RAW Paste Data