-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpicam-record.sh
executable file
·62 lines (51 loc) · 1.4 KB
/
picam-record.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /bin/bash
#
# This script starts picam and record for a given time
# Take in param the number of seconds
# Usage: ./picam-jobs 10
#
# Wait on log: https://superuser.com/questions/270529/monitoring-a-file-until-a-string-is-found
#
# Exit as soon as a command fail
set -e
# Check param
if [ $# -eq 0 ]
then
echo "[error] Need time argument. Usage: ./picam-job <time>"
exit 1
fi
PICAM_DIR=/home/pi/picam
cd $PICAM_DIR
# Initialize log file
echo -n > logs.txt
echo "make dirs..."
./make_dirs.sh
echo "start picam..."
./picam --alsadev hw:1,0 &>$PICAM_DIR/logs.txt & # Forked process
PICAM_PID=$!
# Wait a bit for picam to be ready
#sleep 5
echo "wait for picam to be ready..."
( tail -f $PICAM_DIR/logs.txt & ) | timeout 5 grep -q "capturing started" || # Prevent timeout from exiting
exit_status=$?
# If we reached the timeout, $? contains 124, otherwise 0
if [[ $exit_status -eq 124 ]]; then
echo "[error] Didn't detect 'capturing started' on logs..."
echo "[error] Failed to start picam..."
echo "stop child processes..."
#trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
pkill -P $$
echo "...done!"
exit 1
fi
echo "start recording..."
touch hooks/start_record
sleep $1
echo "stop recording..."
touch hooks/stop_record
ls archive
# Ensure we end child process
echo "stop child processes..."
#trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
pkill -P $$
echo "...done!"