#!/bin/bash
while true
do
    time=`date +%H:%M:%S`
    echo $time
    if [[ "$time" > "01:00:01" ]] && [[ "$time" < "22:30:00" ]]
    then
        ps -ef | grep "TowerOptoSifAndSpectral" | grep -v "grep"
        if [ "$?" -eq 1 ]
        then
            /home/pi/bin/TowerOptoSifAndSpectral &
            echo "process has been restarted!" > /home/data/log.txt
        else
            echo "process already started!"
            sleep 60
        fi
    else
        ps -ef | grep "TowerOptoSifAndSpectral" | grep -v "grep"
        if [ "$?" -eq 1 ]
        then
            sleep 60
        else
            echo "time to kill the task" > /home/data/log.txt
            pkill TowerOptoSifAndSpectral
        fi
    fi
    sleep 30
done
