if [ $# -eq 0 ]
then
echo "Usage:
Run it as root

pkill <duration><suffix><sleep/halt>
duration : integer 
suffix : s - sec
         m - min
         h - hrs
sleep : quits the music player only
halt : quits the music player and turns the iDevice off.
Ex: pkill 10s sleep"
exit 0
fi

if [ $# -eq 1 ]
then

if [ $1 = "--help" ]
then
echo "Usage:
Run it as root

pkill <duration><suffix><sleep/halt>
duration : integer 
suffix : s - sec
         m - min
         h - hrs
sleep : quits the music player
halt : quits the music player and turns the iDevice off.
Ex: pkill 10s sleep"
exit 0
else
echo "Usage error! Type pkill --help for usage details."
exit 1
fi
fi

if [ $# -eq 2 ]
then

if [ $2 = "sleep" ]
then
f1=`ps -ax | grep "/Applications/MobileMusicPlayer" | cut -c 3-5 | head -n 1`
f2=`ps -ax | grep "/Applications/MobileMusicPlayer" | cut -c 3-5 | head -n 1`

if [ $f1 -ne $f2 ]
then
echo "Music player not running."
exit 0
fi

killall Terminal
sleep $1
killall MobileMusicPlayer
exit 0

elif [ $2 = "halt" ]
then
f1=`ps -ax | grep "/Applications/MobileMusicPlayer" | cut -c 3-5 | head -n 1`
f2=`ps -ax | grep "/Applications/MobileMusicPlayer" | cut -c 3-5 | head -n 1`
if [ $f1 -ne $f2 ]
then
echo "Music player not running."
exit 0
fi
killall Terminal
sleep $1
killall MobileMusicPlayer
halt
exit 0
else
echo "Usage error! Type pkill --help for usage."
exit 1
fi

else
echo "Usage error! Type pkill --help for usage."
exit 1
fi

