3

I have a script that's supposed to record a shoutcast stream for an hour, convert it to mp3, and then save it. The script runs correctly when I run it from the terminal, but I can't seem to get it to run in cron (where it should run every hour at the top of the hour).

Here's the line in crontab:

0 * * * * /medialib/tech/bin/recordstream 2>&1 >> /medialib/tech/cron.log

and here's the script:

#!/bin/bash
name="$(date +%s)"

mp3_name=$name.mp3
wav_name=$name.wav

timeout -sHUP 60m vlc -I dummy --sout "#transcode{channels=2}:std{access=file,mux=wav,dst=/medialib/stream_backup/wav/$wav_name" /medialib/tech/lib/listen.m3u

lame --mp3input /medialib/stream_backup/wav/$wav_name /medialib/stream_backup/$mp3_name

rm /medialib/stream_backup/wav/$wav_name

Thank you!

EDIT: Contents of cron.log (This text has been in the log file since it was transferred from an old server where it was working).

VLC media player 2.0.8 Twoflower
Command Line Interface initialized. Type `help' for help.
> Shutting down.
VLC media player 2.0.8 Twoflower
Command Line Interface initialized. Type `help' for help.
> Shutting down.
  • "for an hour" + "0 * * * *" this runs on the hour every hour. I see nothing wrong besides the "rm". You should add something to avoid confirmation (--force) – Rinzwind Jun 06 '14 at 14:44
  • In addition to @Rinzwind's point, my crontab has an additional column between the time and command for the user to run the command under. You might try adjusting your crontab to 0 * * * * root /medialib/tech/bin/recordstream 2>&1 >> /medialib/tech/cron.log I suppose that depends on whether this is /etc/crontab or your user crontab. – rocketman10404 Jun 06 '14 at 14:46
  • Sorry, I was probably fixing that at the same time you were commenting :P – rocketman10404 Jun 06 '14 at 14:52
  • Do you have any message in cron.log? – Rmano Jun 06 '14 at 14:58
  • 2
    I don't think your redirect is working properly. move 2>&1 to the end of the command, then maybe you can get an error message in the logfile. – Dan Jun 06 '14 at 15:19
  • @dan08 that seemed to solve it. I'll confirm when it kicks off at noon. Thanks! – radiotech Jun 06 '14 at 15:37
  • @dan08 that solved it! Thanks for your help! – radiotech Jun 06 '14 at 17:42

1 Answers1

0

Firstly try to see if cron is running

ps -ef | grep cron

If it is not running, start it as root

sudo /etc/init.d/cron start (Ubuntu and Red Hat).

Secondly, check the permissions of the script, if it have the "x" option and then try to run

crontab -e

Try to see if the cron you made is listed with this command

crontab -l

EDIT:

Try to add /bin/bash right before your script call :

0 * * * * /bin/bash /script/file

Any more clues to solve it here.