I am trying to make an AV bug raspberry pi for a class.
I am using sox to record sound. Which is working fine.
the issue is sox needs to be stopped by a control+C to stop and create the new file. If killall is sent from a different ssh session it will drop the other session and sox will not create the file.
listen.sh
#! /bin/bash
NOW=$( date '+%F_%H:%M:%S' )
filename="/home/pi/gets/$NOW.wav"
sox -t alsa plughw:1 $NOW.wav;
sleep 6;
echo $filename
I have tried making a separate script for stopping it; pretty much
killlisten.sh
#! /bin/bash
sleep 5;
ps | grep sox | kill 0;
Then run a
superscript.sh
#! /bin/bash
./listen.sh;
./killlisten.sh;
Any advice on how to stop sox in a way that would still produce an output file would be great. This will ideally be set to run at set times so avoiding human interaction is essential.
Did you %d to ensure that the PID was inputted as an integer? Why not use %s? Just trying to learn, thank you.
– Reckless Liberty Mar 08 '18 at 10:34%d
because I'm assuming that$sox_pid
is an integer. If it's not an integer (for whatever reason), then the statement will generate an error message that can easily be seen. You could obviously use%s
for everything, but I personally tend to use more specific format specifiers if I know that the thing I'm printing is of a particular type. – Kusalananda Mar 08 '18 at 10:42&
starts the given command as a background task, which gives control back to the script immediately. The PID of the command is then available in$!
. Theprintf
is solely for the user, in case they would want to kill the job manually withkill
so that they know what PID to kill (it's not strictly needed). – Kusalananda Mar 08 '18 at 11:09