daily pastebin goal
44%
SHARE
TWEET

npr script

a guest Mar 6th, 2012 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. name=$(basename "$0")
  4. url="http://npr.ic.llnwd.net/stream/npr_live24"
  5. lock=$(pgrep -u "$(id -u)" -xf "mpg123 $url")
  6.  
  7. if [[ "$#" = "1" && "$1" = "play" ]]
  8. then
  9.  
  10.         if [ -n "$lock"  ]
  11.         then
  12.                 echo NPR is already playing.
  13.                 exit 1
  14.         else
  15.                 nohup mpg123 $url >/dev/null 2>&1 &
  16.                 echo NPR start playing.
  17.         fi
  18. elif [[ "$#" = "1" && "$1" = "stop" ]]
  19. then
  20.         if [ -n "$lock"  ]
  21.         then
  22.                 pkill -u "$(id -u)" -xf "mpg123 $url"
  23.                 echo NPR stopped.
  24.         else
  25.                 echo NPR is already stopped.
  26.                 exit 1
  27.         fi
  28. else
  29.         echo "Usage: $name play | stop"
  30.         exit 1
  31. fi
  32.  
  33. exit 0
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top