#!/bin/bash # Start streaming sopcast address $1 with sp-sc, then start mplayer and monitor both processes. # Author: Chickamade and Fernando Sancho PLAYER="mplayer" PLAYERNAME="mplayer" PLAYERARGS="-fs -ontop -vo xv" if ! test $# -eq 1 then echo 'Usage: sopcast ' exit 0 fi if pgrep -f "sp-sc $1" then echo sopcast: channel $1 already streaming, quitting >&2 exit 0 fi PORT=${1##*/} echo sopcast: starting stream $1 on port $PORT >&2 sp-sc "$1" 3908 $PORT >/dev/null & SP_SC=`pgrep -f "sp-sc $1 3908 $PORT"` if test -z $SP_SC then echo sopcast: stream $1 failed to start >&2 exit 1 fi sleep 20 $PLAYER $PLAYERARGS http://localhost:$PORT/tv.asf >/dev/null 2>&1 & PLAYERPID=$(pgrep -f "$PLAYER $PLAYERARGS http://localhost:$PORT/tv.asf") if test -z $PLAYERPID then echo sopcast: $PLAYERNAME failed to start >&2 kill -9 $SP_SC exit 1 fi while true do if ! ps $SP_SC > /dev/null then echo sopcast: stream $1 died, killing $PLAYERNAME >&2 kill $PLAYERPID exit 1 fi if ! ps $PLAYERPID > /dev/null then echo sopcast: $PLAYERNAME not running, killing stream $1 >&2 kill -9 $SP_SC exit 0 fi sleep 10 done exit 0