Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- name=$(basename "$0")
- url="http://npr.ic.llnwd.net/stream/npr_live24"
- lock=$(pgrep -u "$(id -u)" -xf "mpg123 $url")
- if [[ "$#" = "1" && "$1" = "play" ]]
- then
- if [ -n "$lock" ]
- then
- echo NPR is already playing.
- exit 1
- else
- nohup mpg123 $url >/dev/null 2>&1 &
- echo NPR start playing.
- fi
- elif [[ "$#" = "1" && "$1" = "stop" ]]
- then
- if [ -n "$lock" ]
- then
- pkill -u "$(id -u)" -xf "mpg123 $url"
- echo NPR stopped.
- else
- echo NPR is already stopped.
- exit 1
- fi
- else
- echo "Usage: $name play | stop"
- exit 1
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement