Files
AireOptoSifAndSpectral/root/Mywathdog.sh

30 lines
762 B
Bash
Raw Permalink Normal View History

#!/bin/bash
2022-02-18 15:56:30 +08:00
while true
do
time=`date +%H:%M:%S`
echo $time
if [[ "$time" > "01:00:01" ]] && [[ "$time" < "22:30:00" ]]
then
2025-11-19 15:11:44 +08:00
ps -ef | grep "AirOptoSifAndSpectral" | grep -v "grep"
2022-02-18 15:56:30 +08:00
if [ "$?" -eq 1 ]
then
2025-11-19 15:11:44 +08:00
/home/pi/bin/AirOptoSifAndSpectral &
2022-02-18 15:56:30 +08:00
echo "process has been restarted!" > /home/data/log.txt
else
echo "process already started!"
sleep 60
fi
else
2025-11-19 15:11:44 +08:00
pid=$(ps -ef | grep "AirOptoSifAndSpectral" | grep -v "grep" | awk '{print $2}')
2024-08-21 16:59:41 +08:00
if [ -z "$pid" ]
2022-02-18 15:56:30 +08:00
then
sleep 60
else
2024-08-21 16:59:41 +08:00
echo "$?"
2022-02-18 15:56:30 +08:00
echo "time to kill the task" > /home/data/log.txt
2024-08-21 16:59:41 +08:00
kill "$pid"
2022-02-18 15:56:30 +08:00
fi
fi
sleep 30
done