99 lines
2.4 KiB
Bash
99 lines
2.4 KiB
Bash
#!/bin/bash
|
|
|
|
omcbinpath="/usr/local/omc/bin"
|
|
progname=$0
|
|
|
|
function debug_log()
|
|
{
|
|
watcherLogFile=/usr/local/omc/log/cdr_io_proc`date +%Y%m%d`.log
|
|
timestr=`date +%H:%M:%S`
|
|
#echo $timestr
|
|
echo "$timestr $1" >> $watcherLogFile
|
|
}
|
|
|
|
lockfile="/tmp/`basename $progname|awk -F. '{print $1}'`.lock"
|
|
if test -f $lockfile ; then
|
|
exit
|
|
fi
|
|
touch $lockfile
|
|
|
|
|
|
setting=`grep $progname $omcbinpath/dual/sync_source.conf`
|
|
iodir=`echo $setting |awk -F, '{print $5}'`
|
|
procdir=`echo $setting |awk -F, '{print $6}'`
|
|
|
|
localhostnameprefix=`hostname|awk -F'-' '{print $1}'`
|
|
localhostnameid=`hostname|awk -F'-' '{print $2}'|awk -F. '{print $1}'`
|
|
|
|
if test $localhostnameid -eq 0 ; then
|
|
otherhostnameid=1
|
|
else
|
|
otherhostnameid=0
|
|
fi
|
|
|
|
otherserverip=`grep ''$localhostnameprefix'\-'$otherhostnameid'' /etc/hosts |awk '{print $1}'`
|
|
|
|
#echo iodir=$iodir
|
|
#echo procdir=$procdir
|
|
#echo localhostnameprefix=$localhostnameprefix
|
|
#echo localhostnameid=$localhostnameid
|
|
#echo otherhostnameid=$otherhostnameid
|
|
#echo otherserverip=$otherserverip
|
|
|
|
cd $iodir
|
|
|
|
low=`od -x file.index|awk '{print $2}'`
|
|
high=`od -x file.index|awk '{print $3}'`
|
|
((declow=16#$low))
|
|
((dechigh=16#$high))
|
|
|
|
#writing_index=`expr $dechigh \* 65536 + $declow`
|
|
#writing_file=`printf "%06d.dat" $writing_index`
|
|
#echo writing_index=$writing_index
|
|
#echo writing_file=$writing_file
|
|
|
|
sendfiles=`ls *.dat`
|
|
debug_log "Prepare to send files to $otherserverip"
|
|
for file in $sendfiles; do
|
|
processflag=0
|
|
endfile="`echo $file|awk -F. '{print $1}'`.end"
|
|
if test -f $endfile ; then
|
|
processflag=1
|
|
else
|
|
if test `find . -mmin +3 -name $file|wc -l` -eq 1 ; then
|
|
processflag=1
|
|
fi
|
|
fi
|
|
|
|
if test $processflag -eq 1 ; then
|
|
resultfile="`echo $file|awk -F. '{print $1}'`.ret"
|
|
sessionfile="`echo $file|awk -F. '{print $1}'`.finish"
|
|
touch $sessionfile
|
|
expect $omcbinpath/dual/sendfile $otherserverip www 123456 $iodir $file $procdir $iodir/$resultfile $sessionfile
|
|
if test -f $resultfile ; then
|
|
ret=`grep -c '^1' $resultfile`
|
|
else
|
|
ret=0
|
|
fi
|
|
if test $ret -eq 1 ; then
|
|
debug_log "Send $file successfully"
|
|
rm -rf $file $resultfile $sessionfile $endfile
|
|
else
|
|
rm -rf $resultfile $sessionfile $endfile
|
|
debug_log "Send $file unsuccessfully"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
endfiles=`find . -mmin +5 -name '*.end'`
|
|
for file in $endfiles; do
|
|
datafile=`echo $file|awk -F'.end' '{print $1}'`".dat"
|
|
if test ! -f $datafile ; then
|
|
rm -rf $file
|
|
debug_log "Delete $file for nouse"
|
|
fi
|
|
done
|
|
|
|
|
|
rm -rf $lockfile
|