Shell script to restart again
Hi,
I have an audio recording script it that needs to run up to the hour. So I'm trying to get it to start the script again once stopped (at the top of the hour) but it just records the hour and does nothing. Sometimes I even get an illegal number 08 message. Code:
#!/bin/sh |
Quote:
Quote:
Code:
#!/bin/sh |
Quote:
Code:
pid=$(ps -opid= -C audiolog.sh) It might not work like this but it was my logic. |
Ah, I see. First of all cron jobs are tasks that are run periodically. So if you want to start a job on the hour then just start it on the hour. I'd seldomly restart such a process from the same cron job. Problem is that you want to ensure the previous job has finished and decide what to do if not. Luckily process 'arecord' has its duration listed on the command line: 'arecord -f cd -c 1 -d$DURATION -t raw -v -v' (BTW ditch the "-v -v" for "-q" as it's a cron job and any stdout/stderr will be mailed unless specified otherwise. Same goes for 'lame': use "-S") so, at the top of the script, before running any new processes:
Code:
[ while `pgrep -f "arecord -f cd -c 1"` ]; do sleep 2s; done Code:
pkill -15 -f "arecord -f cd -c 1" && sleep 4s; pkill -9 -f "arecord -f cd -c 1" |
Thanks for that. I'm not doing a cron job which would be easier but because I want to see the output displayed in terminal hence the -v -v I could only think of manually executing in terminal once and the script will restart on the hour (which is after the recording finishes). This way I can just open up terminal and straight away see it's working.
|
You could turn the script into a cron job and use 'logger' statements to tell you about progress:
Code:
_retVal() { case $? in 0) RETVAL="OK";; *) RETVAL="EPIC FAIL";; esac; } Code:
grep audiolog.cron /var/log/messages |
Use timeout?
Code:
while true; do timeout 1h ./Desktop/audiolog.sh; done Code:
pid=$(ps -opid= -C audiolog.sh) Basically, while the directory /proc/$pid exists, do sleep 1, then if while completes successfully, do ./Desktop/audiolog.sh |
On my system that 'while' loop never ends. I would solve this by dividing your script into two parts: audiolog.sh - this contains only arecord commands and script to mange the 'audiolog.sh'. say let call this audioctl.sh. Now you put the 'while' loop into audioctl.sh. All the process will by started by running audioctl.sh only.
|
All times are GMT -5. The time now is 10:17 AM. |