Having issues with saving SoX audio recording using cron jobs
Hi there I'm new to all of this and I'm not sure if I'm using the wrong approach. I am trying to record the audio that i pipe to SoX recorder at certain times of the day and I'm doing this using a cron job on the Raspberry PI 3b that looks like this:
10 * * * * timeout -s 2 60 sh home/pi/test.sh test.sh works just fine if i type it into the command line manually and it saves the file. The shell script looks like this: #!/bin/bash [some command that plays audio]| rec /home/pi/test.wav This script runs and saves the audio file if I run it in terminal and stop it with ctrl + C. So i assumed not using ctrl + C in cron this was the issue so I tried pkill and exit as below to terminate the script: #!/bin/bash timeout -s 2 50 bash -c "[some command that plays audio]| rec /home/pi/test.wav" sudo pkill rec exit When i run this script in terminal it exits after the 50 seconds and terminates without me manually pressing ctrl + C and i get a saved audi file. However when i run it as a cron job i get the same issues with no audio saving. I also tried: #!/bin/bash timeout -s 2 50 bash -c "[some command that plays audio]| XDG_RUNTIME_DIR=/run/user/1000 rec /home/pi/test.wav" sudo pkill rec exit I saw adding XDG_RUNTIME_DIR=/run/user/1000 solved the issue for some people who used arecord. I get a file while running the cron job using the above script but it is empty and consistently 44 bytes. I even tried it using arecord and got the same issue. I have no idea what i am doing wrong. Any help will be appreciated. Thank you |
Quote:
home/pi/test.sh should be /home/pi/test.sh Won't test.sh run by making it executable? Code:
chmod 744 test.sh https://www.linuxquestions.org/quest...ile%27-719553/ https://unix.stackexchange.com/quest...sa-loop-device Are you trying to capture the output of the sound device? From some executable running? Only way that you can get it? |
Thanks for your reply
Quote:
Quote:
Quote:
|
If something works when started manually, and doesn't work when started by cron, the first thought should be "PATH". Your interactive shell usually has a much richer PATH variable than cron.
If that is the problem in your case, the solution is to launch all commands and scripts using their absolute pathname (i.e. starting with slash). |
Quote:
|
Quote:
Quote:
|
Quote:
Another guess: the rec command might expect some files (input, output or intermediate files) at relative locations which don't make sense when launched by cron. Can file locations be configured? You could also launch rec with an option like --verbose or -V4 to get debugging messages. |
Quote:
According to syslog it runs: Dec 23 23:41:01 raspberrypi CRON[3370]: (pi) CMD (timeout -s 2 60 sh /home/pi/test.sh) I only get a warning when running in terminal manually but that doesn't seem to be the problem since it works /usr/bin/rec WARN alsa: can't encode 0-bit Unknown or not applicable Quote:
This is the full script i try running Code:
#!/bin/bash |
Quote:
Rather than using sudo in a cron script, I would run the script under root's cron table. |
Quote:
I edited the sudo cron table to run the script below: Code:
I think I will look into scheduling with the 'at' command |
same problem ! Still no solution ?
everything is in the title. If alwaysaskindalost read this message and have found a solution to his problem, I take !
|
Quote:
AFAICS they already contain a solution, and more. |
@odoho
Hi Odoho, you must have vision much more efficient than mine. Last post of alwayskindalost was
The empty file unfortunately does not even appear in the recordings folder now. It still works in terminal. I am really unsure of what I am doing wrongThis doesn't sound as if his problem was solved ;-) Meawhile, I moved ahead. It didn't work cause I connected a USB microphone. Once I have changed by a regular microphone, it works. I guess the computer puts the USB microphone in higher priority than the front socket for regular microphone, and that this priority is lost in the CRON, explaining why it works only in the terminal. I tried and find out how to select the audio input in the REC command, and didn't find anything, but that's another topic... |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 08:53 PM. |