LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-23-2006, 03:03 AM   #1
evaristegalois
Member
 
Registered: Sep 2006
Distribution: Ubuntu 14.04
Posts: 41

Rep: Reputation: 15
mplayer and cron


I run Ubuntu 6.06 with linux kernel 2.6.15-27-386 on an IBM Thinkpad laptop.

Here is my question: I want to schedule recordings of internet audio streams (public radio) and automatically convert them to mp3 files for my ipod. I use mplayer to dump the audio stream into a ram file. Then I use mplayer again to convert the ram file to a wav file. Then lame to convert the wav file to a mp3 file.

All of this works without a hitch except the step from ram to wav. The odd thing is that this can easily be done on the command line:

/usr/bin/mplayer -vo null -vc dummy -af resample=44100 -ao pcm:file=/directory/test.wav /directory/test.ram

Yet when I put this line verbatim into my crontab file:

52 0 23 12 * /usr/bin/mplayer -vo null -vc dummy -af resample=44100 -ao pcm:file=/directory/test.wav /directory/test.ram

The result is a wav file which is interrupted after ten seconds. You always hear the first ten seconds, no matter how long the original file is, and then nothing.

What could it possibly be about this command running in cron that doesn't make it work, as opposed to running it on the command line?

Your help is appreciated!
 
Old 12-23-2006, 10:53 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Remember cron doesn't inherit environment. When you login you create an environment because you get /etc/profile, /etc/bashrc, $HOME/.profile, $HOME/.bashrc and any other sourced file. You also run a full shell (typically bash on Linux). Cron runs a simple shell and does not source all these files.

It may be that this isn't working because it is relying on some environment variable that isn't there when you run it in cron.

You could try putting it in a script that includes the shell and any of the environment variables that you have at command line (even just sourcing them).

Also remember you have a display device attached when you are logged in but cron has no output device. You might want to make sure you add redirect to /dev/null at end of your cron entry:
>/dev/null 2>&1

So your script should start with the shell you want:

#!/bin/bash

You could then set the variables or you could source in the same files you do when you login:

. /etc/profile
. /etc/bash
. <full path to user home>/.profile
. <full path to user home>/.bashrc

then after all that add your command line. In cron you would then tell it to run the script rather than the command. You also put the redirection to /dev/null mentioned above.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
Slackware's Cron Scheduler: I'm thinking maybe I need to put in a different cron? Old_Fogie Slackware 5 11-03-2006 06:25 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration