-
Notifications
You must be signed in to change notification settings - Fork 5
/
launch_epaper.sh
executable file
·60 lines (55 loc) · 1.23 KB
/
launch_epaper.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
#!/bin/bash
# launch_epaper.sh
# navigate to directory then execute python script
ePaperClockLocation="/home/$USER/e-Paper/RaspberryPi_JetsonNano/python/examples/"
# Initialize our own variables
verbose=0
clock=0
local_run=0
# Parse command-line arguments
while (( "$#" )); do
case "$1" in
-v | --verbose)
verbose=1
shift
;;
--clock)
clock=1
shift
;;
--local_run)
local_run=1
shift
;;
*)
echo "Error: Invalid option"
exit 1
;;
esac
done
runscript() {
if ! pgrep -f "python3 main.py" >/dev/null; then
# Construct the python command with the parsed arguments
python_cmd="python3 main.py"
[ "$verbose" = 1 ] && python_cmd="$python_cmd -v"
[ "$clock" = 1 ] && python_cmd="$python_cmd --clock"
[ "$local_run" = 1 ] && python_cmd="$python_cmd --local"
echo "Running command: $python_cmd"
if [ "$verbose" = 1 ]; then
$python_cmd
else
$python_cmd 2>>failures.txt
fi
if [ $? -ne 0 ]; then
echo -e "Failure occurred in main.py at: $(date '+%Y-%m-%d %H:%M:%S')\n" >>failures.txt
fi
fi
}
cd $ePaperClockLocation
while true; do
runscript
sleep_duration=60
echo "Sleeping for $sleep_duration seconds"
sleep $sleep_duration
sleep 60
done