I listen to various internet radio stations through out my day and sometimes I just don?t have the time or am I in front of a computer at
the time. This prompted to write a script that gets run in the background by a cron job and quietly kills itself after a predetermined amount of time. The only requirement would be mplayer, a radiostream and a simple cronjob.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| #!/bin/bash
# rip_steph_miller_show
source_stream="mms://38.116.147.100/SMS?MSWMExt=.asf"
dest_directory="/home/lando/podcasts/steph_miller/"
prefix="steph_miller"
postfix="asf"
date=`date +%Y-%m-%d`
dest_file="${dest_directory}${prefix}-${date}.${postfix}"
mplayer -dumpstream ${source_stream} -dumpfile ${dest_file} &
pid=$!
let "sleeptime=60*60*3" # 60secs*60mins*3hours = 3 hours
sleep ${sleeptime}
kill -15 $pid |
grab the above bash script and replace the source_stream with the address to the stream you want ripped, then the dest_directory to where you want to save the ripped stream and finally replace the prefix to the name you want the saved rip stream to have and the postfix to the same extension the stream has.
No matter what you choose the prefix to be the file will be saved with the date added to keep from overwriting itself the next time the script
is run.
Save the script and place it in a safe out of the way directory where your cronjob can access it from. now we can take a look at the cron line that needs to be added.
0 9 * * 1-5 bash /home/lando/scripts/rip_steph_miller_show >/dev/null 2>&1
to access your users crontab enter the command “crontab -e” and enter the above cron line. This cron line will run every weekday at 9 am. for more information on crontabs you can visit this wiki or google crontabs for hundreds of examples.
The first couple of numbers and ?*?s are what tells the cronjob when to execute. immediately after your have the command to execute and at the very end any output that might end up in logs or mailed to your will be redirected to /dev/null. I wont go into a whole crontab tutorial because it really is a simple concept and there are already enough of those about.
hope this script help somebody and im rather new to bash scripting if anyone has any improvements let me know. kthxbye!