LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Perplexing Cron audio problem (https://www.linuxquestions.org/questions/linux-newbie-8/perplexing-cron-audio-problem-4175521370/)

rmcellig 10-07-2014 05:28 PM

Perplexing Cron audio problem
 
I'm running LinuxLite 2.0 32bit on a Dell 3000.

I have never come across anything like this and to tell you, I am stumped.

Here are the contents of my crontab file:

Code:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow  command
*/10 * * * * /usr/bin/arecord -t wav -f cd -d 42 /home/randy/Music/lanting$(date "+\%^b\%d\%y").wav


If I run this from the terminal, everything is fine. It properly records the audio:

Code:

/usr/bin/arecord -t wav -f cd -d 42 /home/randy/Music/lanting$(date "+\%^b\%d\%y").wav
If I run this as it is shown in my crontab file, it records but there is no audio recorded.:


Code:

*/10 * * * * /usr/bin/arecord -t wav -f cd -d 42 /home/randy/Music/lanting$(date "+\%^b\%d\%y").wav
What could be causing this? I tried different cron settings for example 15 14 * * 2

This recorded at 2:15pm on Tuesday (today) but no audio. Yet if I run the code as mentioned above, from the terminal without the cron settings, the recording is fine.

Any ideas what I should do?

Kustom42 10-07-2014 05:45 PM

The first thing that comes to mind is that cronjobs will not load any environment variables that your shell will have set when it loads your .bashrc and other profile files. Are there any environment variables you can see being set that would have any affect on your arecord binary?


Im not familiar with arecord so not sure how it works but I would assume that its an environment variable

Kustom42 10-07-2014 05:52 PM

Yea looks like its environment variables.

Couldnt find really anything online except the archwiki which describes it.

Should translate to any distro as its a standalone binary. Try creating a .asoundrc file with the values set and call that in your cronjob script.

https://wiki.archlinux.org/index.php...nment_variable

JeremyBoden 10-07-2014 05:52 PM

A trial gives the following:-
Code:

zzz=$(date "+\%^b\%d\%y")
echo $zzz
\OCT\07\14

Perhaps you could try $(date "+/%^b/%d/%y")

rmcellig 10-07-2014 05:56 PM

For some reason things seem fine now. I will keep an eye out for any other anomalies. At the moment, I have several Crons recording at different hours to see if everything is OK.

Thanks for the tips!!

Regarding the .asoundrc file mentioned above, where would I create this file, exactly what would I enter in the file and finally how do I call this in my cronjob script. This is a new one for me so I want to make sure I get everything right and learn from it.

Thanks again!!!!

Kustom42 10-07-2014 05:57 PM

Quote:

Originally Posted by JeremyBoden (Post 5250499)
A trial gives the following:-
Code:

zzz=$(date "+\%^b\%d\%y")
echo $zzz
\OCT\07\14

Perhaps you could try $(date "+/%^b/%d/%y")

That could very easily be a valid structure, not something a Linux guy likes to see but you can create files with "\" in it or whatever character you want.

A good interview question I ask is:
"A file has been created named * at /. How would you delete the file with rm without removing anything else?"

Kustom42 10-07-2014 05:58 PM

rmcellig,

please take a look at the links provided. It is going to be your environment variable for hte default soundcard/microphone as those get set when you start a shell but not when a cron job is run. If the same command works when run manually and you are not getting an error that a file is not found its not an issue with a file path.

rmcellig 10-07-2014 08:15 PM

Thanks!!

rmcellig 10-09-2014 11:26 AM

I have Zorin 9 lite and Linux Lite 2.0 in seperate partitions on my Dell 3000. In Zorin, I have no problems at all recording from my crontab. The problem appears in Linux Lite. Why is this and what can I check in Zorin that may be missing in Linux Lite that may resolve my problem? I'm so new to all of this but at the same time I want to learn why these things happen.

If there is any info you would like me to post back while booted into Linux Lite, let me know.

Thanks again!!

rmcellig 01-06-2015 06:03 PM

Still not working
 
I just did a brand new installation of Linux Lite 2.2 on my Dell 3000. Cron still doesn't work. No audio. Works when I run the following from the terminal but not in my crontab. I tried to keep the code as simple as possible.


Run from Crontab:
Code:

*/10 * * * * /usr/bin/arecord -t wav -f cd -d 44 /home/randy/Music/test.wav
Run from the Terminal:
Code:

/usr/bin/arecord -t wav -f cd -d 44 /home/randy/Music/test.wav

Miati 01-06-2015 08:41 PM

do you get any errors? crontab will send errors to your linux email (type mail in terminal) of output it has. You can also redirect the output by using > or >>

Code:

*/10 * * * * /usr/bin/arecord -t wav -f cd -d 44 /home/randy/Music/test.wav &>> /tmp/cron_arecord.log
Look through that to see if anything pops up.
Also crontab uses sh, not bash. I don't see anything that should be of issue, but in terminal try typing sh, then typing or copying in your command.

Quote:

"A file has been created named * at /. How would you delete the file with rm without removing anything else?"
Escape it? :P rm -i /\*
& if you're unsure, use autocomplete & -i.
Do I get a job? ;)

rmcellig 01-07-2015 06:27 AM

This is what I get :

Code:


randy@lin3000:~$ sh /usr/bin/arecord -t wav -f cd -d 84 /home/randy/Music/chu3.wav
/usr/bin/arecord: 1: /usr/bin/arecord: Syntax error: word unexpected (expecting ")")
randy@lin3000:~$


Miati 01-07-2015 10:12 AM

Quote:

Originally Posted by rmcellig (Post 5296972)
Code:

randy@lin3000:~$ sh /usr/bin/arecord -t wav -f cd -d 84 /home/randy/Music/chu3.wav
/usr/bin/arecord: 1: /usr/bin/arecord: Syntax error: word unexpected (expecting ")")


Sorry, I wasn't clear enough.

In a terminal, type in sh then hit enter. This enters the sh shell. Then type in the script name
It'll look like this:

Code:

~ $ sh
$
$ /usr/bin/arecord -t wav -f cd -d 84 /home/randy/Music/chu3.wav

For your earlier post, this is what I get what I run echo $(date "+\%^b\%d\%y").wav in bash and sh
Code:

~ $ echo $(date "+\%^b\%d\%y").wav
\JAN\07\15.wav
~ $ sh
$ echo $(date "+\%^b\%d\%y").wav
.wav


jpollard 01-07-2015 01:57 PM

Quote:

Originally Posted by rmcellig (Post 5296691)
I just did a brand new installation of Linux Lite 2.2 on my Dell 3000. Cron still doesn't work. No audio. Works when I run the following from the terminal but not in my crontab. I tried to keep the code as simple as possible.


Run from Crontab:
Code:

*/10 * * * * /usr/bin/arecord -t wav -f cd -d 44 /home/randy/Music/test.wav
Run from the Terminal:
Code:

/usr/bin/arecord -t wav -f cd -d 44 /home/randy/Music/test.wav

You may be having a user access conflict. If you are not logged in, you don't own access to the audio.

The GUI login generally sets up access permissions to allow GUI interfaces to have access. When logged out, access is denied as it could be a security violation (as in surreptitious recording of data where people believe they are in private).

My system has two users (me, and my wife). When both of our logins are active, only the one with the GUI is granted access, and the other is disabled - providing nothing, and playing nothing. When the other switches in, and logs in (usually the screen saver), then the sound resumes - and the other is disabled.

Shadow_7 01-07-2015 10:07 PM

Just guessing. You need to identify what user it is running as under cron (nobody?). And ensure that user has access (audio group?) and write permissions to the destination. Check the /etc/default/cron file for settings, and maybe change the logging level and check /var/log/ for why it's failing. Or if it's failing, I tend to stop cron entirely on my desktop installs. I'm not a big fan of logfile rotations in the middle of a boss fight. Or 6:25am noisy drive alarm clocks.


All times are GMT -5. The time now is 10:41 AM.