Recording Internet Radio Part 2 - or - How to Automate Tasks in DSL

-- June 26, 2006 update. go to to copy the scripts. There is a small problem with how they display on this page

Now that we have a nice script to start recording a radio stations
streaming broadcast it would be nice if we could have that script
start up at a predefined date and time. It would be equally nice to
be able to stop that script from recording at a predefined date and

Lets work on the stopping part first.

Basically we need a script that will search for our recording script
from all the other processes that are running. Then get the Process ID
(PID) and issue a KILL command.

I think this script may do just that:

# This script will find all processes matching the argument characters
# it then tries to remove itself from that list and kill the remaining
# CAUTION !!! If you run this script with an argument of 'abc' it
will also
# find process 'abc1', 'abcdefg' etc.
# usage: kill|echo searchString
# if first parm is 'kill' then any processes found will be
issued the kill command


if [ ! -z "$2" ]; then

PIDS=`ps -ax | grep $PROCESS | sed -e "s/.*$scriptName.*//" -e "s/.*grep $PROCESS*//"|awk '{ print $1 }'`
if [ ! -z "$PIDS" ]; then
if [ $1 == "kill" ]; then
ps -fp $PIDS
kill $PIDS
ps -fp $PIDS
echo No process $PROCESS in process list

echo USAGE : $scriptName "kill|echo searchString"
echo "Caution - unintended tasks may be killed use echo parm

I don't want to go into this script too deeply but here's how you use
it after you save it as and make it executable. In a
console you could enter " echo WMUB" and it would lists all
the running tasks that have the string 'WMUB' in them. The 'echo' as
the first parameter tells the script to just list the processes, not
kill them. Try this with the script running. In a
xshell issue the "ps -ax" command to see what's currently running.
Then issue the " echo WMUB" command and you'll see
something like:

dsl@DSL22rc1:~$ echo WMUB
Warning: bad syntax, perhaps a bogus '-'? See
dsl 32230 32221 0 17:45 ttyp1 S 0:00 /bin/sh
dsl 32232 32230 0 17:45 ttyp1 S 0:00 /bin/sh
dsl 32233 32232 0 17:45 ttyp1 S 0:00
/opt/mplayer/bin/mplayer -pla

To actually kill the recording tasks you would enter " kill
WMUB" and you'd see something like this:

dsl@DSL22rc1:~$ kill WMUB
Warning: bad syntax, perhaps a bogus '-'? See
KILLING WMUB pid=32230 32232 32233
dsl 32230 32221 0 17:45 ttyp1 S 0:00 /bin/sh
dsl 32232 32230 0 17:45 ttyp1 S 0:00 /bin/sh
dsl 32233 32232 0 17:45 ttyp1 S 0:00

Be very careful with this script. Make sure you give it
enough characters to uniquely identify the task you want to stop.

So now we have a way to stop a process but what about automating

Many distributions of Linux contain something called Cron. It's used
for scheduling things, like run this script on this day at this time
or run this program on this day at this time. The Damn Small Linux
distribution doesn't have Cron. From what I've been told you can add
it with apt-get but I haven't done that. Instead I've written another
script that is good enough for what I need.

The script called runs in the background and every 30
seconds checks to see if something needs to be done at this time. The
list of things that need to be done are kept in /home/dsl/cronIN.txt
file. They have a YYYYmmddHHMM date-time stamp followed by the
command to be issued. So the cronIN.txt file might look like this to
start recording a broadcast from WMUB on March 31, 2006 at 10pm (2200
hours) and end it one hour later, at 2300 hours.

200603312300 kill WMUB

The "<end>" needs to be the last line of the cronIN.txt file. You can
enter as many date-time stamped tasks as you like. As each task is
executed by it will be logged to the file called
/home/dsl/cronLOG.txt and removed from the file cronIN.txt.

One way to run would be to open a shell and then issue the
command "" and watch it run. It produces a message each
time it wakes up and checks for work to do. This works fine and is
probably a good way to experiment with creating cronIN.txt tasks.
After you're use to how it works you can add a line to your .xinitrc
(it's a hidden file in your home directory.) to start the
script when you start your X window manager. To capture the messages
from the script the line would look something like this:

/home/dsl/ >/home/dsl/cronMSG.txt &

or for no output messages use:

/home/dsl/ >/dev/null &

Either way the cronIN.txt and cronLOG.txt files work the same.

Here's the actual script. Copy it and make it executable.

# for those without a cron...
# Required files:
# 1. cronIN.txt
# Last line contains "" in cols 1-5
# All other lines should have timestamp in col 1-12
# blank in col 13
# command to be
executed starting in col 14
# 2. cronLOG.txt
# As commands are executed they are copied to this file with the
# timestamp when they were executed put in front.
# Temporary file:
# 1. cronOUT.txt - temporary file that becomes cronIN.txt
while true
exec 3< cronIN.txt
thisRun=`date +%Y%m%d%H%M`
echo $thisRun "fauxCron checking..."
read taskTime taskCommand > cronLOG.txt
echo $taskTime $taskCommand >> cronOUT.txt
read taskTime taskCommand > cronOUT.txt
exec 3>&-
if [ $activityThisRun == "YES" ]; then
rm -f cronIN.txt
cat cronOUT.txt > cronIN.txt
rm -f cronOUT.txt
sleep 30s
exit 0

Well... that's it. With you can automate some tasks in
DSL and with you can kill tasks (and probably shoot
yourself in the foot....). I hope you can use them and get enjoyment
from them. While I've made every attempt to make sure these scripts
work properly it's important to know that they could have errors in
them that may cause data loss or worse. These scripts are not
supported by the makers of Damn Small Linux and should be run at your
own risk.

I welcome questions or comments but I don't check this blog area very
much so you might get a quicker answer by posting your question in the
forum area.

My thanks go out to everyone involved with the creation of Damn Small
Linux and the users who contribute to the DSL extentions and forums.

Good Luck,
newolduser at gmail dot com