Time To Earn

Saturday, August 24, 2013

Script for checking the file older than 10 minutes

#!/bin/ksh
export job_status=0
export ENV=abc
export log_path=/var/opt/logs
export log_file=/tmp/check.log
export fail_dir=/var/opt/fail
#export log_path=/home/vivt
rm $log_file
cd $log_path
touch test_check_temp.inprog
sleep 600
export latest_log=`cd ${log_path};ls -ltr lnk* | tail -1 | awk '{ print $9 }'`
if [[ test_check_temp.inprog -ot $latest_log ]];then
        echo 'The test job is running fine' >> $log_file
        rm $fail_dir/*
else
        echo "The job is hung" >> $log_file
        job_status=1
        touch $fail_dir/test_job_hung
fi
rm test_check_temp.inprog
if [[ $job_status -eq 1 ]] ; then
        echo "The test job is hung " | mailx -s "job is hung " -m $RECIPENTS
        if [[ $? -eq 1 ]];then
                echo 'No E-mail' >> $log_file
        else
                echo 'E-mail sent ' >> $log_file
        fi
else
        echo 'The job running fine' >> $log_file
        rm $fail_dir/*
fi

No comments:

Post a Comment