[SATLUG] The typical CRON DOES NOT WORK post...

Marc Ripley misteratomic at gmail.com
Thu Jan 22 13:43:06 CST 2009

Ah, I've beat my head in enough and I ask for help with CRON.

I have a script which works fine when I'm logged in but (THE SOUND OF
SCREAMS IN HORROR) does not work in CRON!
Yes, the typical cron question thread.

However, I've got a couple of question and your answers may help me
sort things out.

First, I have two types of user cron jobs created with my account.
One works, the other does not.
Here is the one that works....

Here is the script that is called by cron:

echo "MythPretty Ran: $(date)" >> /tmp/croncheck.log
cd /var/lib/mythtv/recordings
mythrename.pl --link /var/lib/mythtv/showlink --format %T/%S%-%Y-%m-%d

and now the crontab entry for this item.

# m h  dom mon dow   command
01 * * * * /usr/local/bin/mythpretty.sh >/dev/null 2>&1
31 * * * * /usr/local/bin/mythpretty.sh >/dev/null 2>&1

Works fine now.  It used to fail until I added the path.

Now, I'll include the one that fails.
Script to call arecord, then lame, then delete a file.

echo "C2C HR1 Recorded: $(date)" >> /tmp/croncheck.log
cd /home/marc/Desktop
/usr/bin/arecord -d 3300 -c 1 -f S16 -r 32000 -D hw:2,0 C2C_`date
/usr/bin/lame -v -V9 C2C_`date +%y_%m_%d`_H1.wav C2C_`date +%y_%m_%d`_H1.mp3
rm C2C_`date +%y_%m_%d`_H1.wav

And the relevant crontab entry

# m h  dom mon dow   command
01 * * * * /usr/local/bin/mythpretty.sh >/dev/null 2>&1
31 * * * * /usr/local/bin/mythpretty.sh >/dev/null 2>&1
06 00 * * * /usr/local/bin/c2c-h1.sh >/dev/null 2>&1

The script "c2c-h1.sh" works from a terminal while logged into the
machine.  It will also run from cron as long as I am logged into an
gnome session.
It does not work in cron nor if I log in from remote ssh if I am NOT
logged into my account via gnome.  If I do try arecord -l from remote
ssh I get a "arecord: device_list:215: no soundcards found..." in the
cron nor remote ssh login can seem to execute arecord.  So, is this an
issue than the environment is not set correctly?  Will the environment
properly let the system know that there are indeed soundcards in this
machine when I'm not logged into a gnome desktop?  Does arecord
require xwindows and therefore need to set a display?

By the use of the echo command at the beginning of my scripts, I know
that cron is running the job or at least trying.

If I have to include my login environment, how do I place this in the
crontab line or for that matter, in the script?  Again, cron is
running the script, I suspect that arecord is the issue.
I have tried including the full path of arecord in my script but the
result is the same.  I once had the cron job start while I was logged
in and next process lame while I was logged out.  Strange!

Any help would be appreciated and SUPER THANKS in advance.


More information about the SATLUG mailing list