Hi All,
I'm trying to write a script which will do following :
- For any old log under trace directory, if found move it to Archive
- Check for a process �process-A� if it is running abort from the script
- Else start it up (start_process-A.sh this case)
- If it fails to start the process, exit with the appropriate exit code
- All of the above steps will be logged in the log file under trace
#!/bin/ksh
SERVICE='process-A'
JOB=`basename $0`
OWNPID=$$
LOGFILE=$HOME/trace/$JOB$OWNPID.log
Archive=$HOME/trace/Archive
archive()
{
if [ -f $HOME/trace/ start_process-A.sh.*.log ]; then
mv $HOME/trace/ start_process-A.sh.*.log $Archive
else
echo "No file to archive" | tee -a ${LOGFILE}
exit 1;
fi
}
>>>> The above function moves all the files to the Archive directory as I used wildcard (*) but I want to keep the latest file (which will be generated upon completion of this script) in the trace directory and rest in the Archive directory. I have done lots of search in the google and just cannot find it. Any help will be appreciated.
# Checking process-A .. if not found - equals to 1, start it
ps -ef | grep $SERVICE | grep -v grep
if [ $? -eq 1 ]
then
echo "`date` : $SERVICE is down, starting up ..." | tee -a ${LOGFILE}
$HOME/ start_process-A.sh | tee -a ${LOGFILE}
else
echo "`date` : $SERVICE is up ..aborting from the script" | tee -a ${LOGFILE}
fi
#Moving old log file into Archive directory
archive
>> Is there a was to check the start_process-A.sh script is failed or hung? if so how do I redirect it to the log file?