#!/bin/sh
# let 做整数运算
let fst_tag=0
file_path='/home/womail/sendmail/file'
while true
do
let month=`date +%Y%m`
let day=`date +%d`
HOUR=`date +%H`
let hour=`echo $HOUR|bc`
minute=`date +%M`
echo 'sysdate='$day'-'$hour':'$minute
if [ $hour -ge 7 -a $hour -le 17 ]
then
let process_tag=`ps -ef | grep sendmail | grep -v grep | wc -l`
if [ $hour -eq 7 -a $fst_tag -eq 0 -a $process_tag -eq 0 ]
then
last_day=`date -d '1 days ago' +%Y%m%d`
cur_day=`date +%Y%m%d`
for file in `ls $file_path/*$last_day* $file_path/*/*$last_day* | grep -v flag`
do
new_file=`echo ${file/$last_day/$cur_day}`
echo 'old_file='$file';new_file='$new_file
mv $file $new_file
done
echo 'start_java first'
cd /home/womail/sendmail
nohup java -jar -Xms128m -Xmx1024m /home/womail/sendmail/20140610_sendmail.jar >> /home/womail/sendmail/logs/send_mail.log &
cd /home/womail/sendmail/sh
let process_tag=`ps -ef | grep sendmail | grep -v grep | wc -l`
if [ ${process_tag} -eq 1 ]
then
let fst_tag=1
fi
fi
if [ $hour -eq 17 -a $fst_tag -eq 1 ]
then
let fst_tag=0
fi
interrupt_file='/home/womail/sendmail/file/flag/'$month$day'.txt'
echo 'interrupt_file='$interrupt_file
#if [ $process_tag -eq 0 -a -f ${interrupt_file} ]
if [ $process_tag -eq 0 ]
then
echo 'start_java'
cd /home/womail/sendmail
nohup java -jar -Xms128m -Xmx1024m /home/womail/sendmail/20140610_sendmail.jar >> /home/womail/sendmail/logs/send_mail.log &
cd /home/womail/sendmail/sh
fi
fi
sleep 60
done