0

I wrote a script that should check if the arecord command line audio recorder is not working, and if so it should start it. With the help of cron, I want to verify that I'm recording within a specific time frame. Thid is because sometimes the arecord stop without any warning.

Here is my script (a shell executable file) I run with cron:

#!/bin/sh
dateis=$(date +"%Y-%m-%d-%H-%M")
if [pgrep -x "arecord" >/dev/null]
then 
    
else 
    arecord -v -f dat -r 48 -D hw:1,0 -d 200 -c 2 | lame -r -h - record-$dateis.mp3
fi

For some reason, even when the arecord is recording, it tries to start another instance of arecord. On the command line, the pgrep is indicating properly. But for some reason it won't stop and would ignore the if statment. It starts recording even though it is running at the same moment.

Hope I made this issue clear.

4
  • [pgrep -x "arecord" >/dev/null] should attempt to open a file named /dev/null] and execute a command named [pgrep - both of which should result in errors. Are you sure that's exactly what your script contains? Dec 22, 2020 at 23:37
  • 2
    paste your code into shellcheck.net for help with syntax errors. Dec 23, 2020 at 1:57
  • thanks @glennjackman ! a great tool!! Dec 24, 2020 at 0:33
  • What is your OS? Dec 24, 2020 at 10:18

1 Answer 1

0

You probably need

#!/bin/sh
dateis=$(date +"%Y-%m-%d-%H-%M")
if pgrep -x "arecord" >/dev/null
then
    :
else
    arecord -v -f dat -r 48 -D hw:1,0 -d 200 -c 2 | lame -r -h - record-$dateis.mp3
fi

I've tested this, it did what you want.

8
  • did it (thanks) and still - it continues to start a new recording before the arecord stop the previus one... Dec 24, 2020 at 0:34
  • What does "file $(which arecord)" give you? Dec 24, 2020 at 3:05
  • interesting... when i use "file $(which arecord)" i get "usr/bin/arecord: symbolic link to aplay" and when i do "fle $(which aplay)" i get all the detals Dec 24, 2020 at 8:11
  • 1
    Could be the reason "pgrep -x" doesn't work. Dec 24, 2020 at 8:14
  • O.K. but i really don't understand it. cause i can see the proccess. when i do "pidof arecord" get a number (the pid prosumably) and when i do pidof "aplay" i get nothing... Dec 24, 2020 at 8:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .