#!/bin/sh
export TERM=linux
start()
{
logger "starting logs..."
NOW=$(date +"%F")
FILE="log-$NOW"
sh -ci "myapp -w /opt/home/logs/$FILE &> /dev/tty${#} &" >> /dev/null
wait
logger "myapp started"
}
stop()
{
kill -9 $(pidof myapp)
}
CDAY=$(date +"%d")
start
while [1]; do
if [ $CDAY -ne $(date +"%d") ]
then
logger "loop"
CDAY=$(date +"%d")
stop; start
fi
done
the logic is next: myapp starts to log some process if current day has been changed (next day came) script stops myapp and launch it again for new log file creation
I am new with shell scripting and it doesn't work as assumed, where am I wrong?
UPD: seems that while loop doesn't work, script doesn't go in it, no logger "loop" in logread
UPDD: done
corrected syntax of while loop to
while : and it starts to work.
Thank you all!
$:/dev/tty${#}assuming you want the number of arguments passed.(( $CDAY != $(date +"%d") ))and for better style a function called stop should not start also. Either rename torestartor usestop; startin the while loop.