UPDATED
Try something like this (OP's code modified a little bit):
#!/usr/bin/bash
stop() { [ $CPID -ne 0 ] && kill -INT $CPID && wait $CPID && echo "Killed $CPID"; }
trap "stop; exit" INT
CPID=0
while :; do
read -p "Enter your number here: " YOURNUMBER
stop
[ "$YOURNUMBER" == quit ] && break;
TIMESTAMP=$(date +"%Y.%m.%d_%H.%M")
avconv -f video4linux2 -r 3 -fs 52428800 -i /dev/video0 /home/$USER/orders/$YOURNUMBER/$TIMESTAMP-$YOURNUMBER.avi&
CPID=$!
echo -e "Video complete!"
done
This starts avconv in the background so the user can enter a new number. Maybe the stdout and stderr of avconv should be redirected to a log file or to /dev/null. Also it should be tested which signal stops avconv gracefully. -INT
is equivalent to ctrl+c. It it does not work, try -HUP
, -TERM
or even -KILL
if nothing else helps. Maybe You should implement a trap
to catch INT
signals to kill the last avconv it ctrl+c is pressed.