add bin/mib conf dual file

This commit is contained in:
2024-10-19 15:36:39 +08:00
parent 8feba9929d
commit 6156304aed
99 changed files with 66362 additions and 1 deletions

54
bin/dual/cdr_data_proc.sh Normal file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
omcbinpath="/usr/local/omc/bin"
mysqlbin="/usr/bin/mysql"
mysqluser="administrator"
mysqlpwd="*86#ROtartsinim"
progname=$0
function debug_log()
{
watcherLogFile=/usr/local/omc/log/cdr_data_proc`date +%Y%m%d`.log
timestr=`date +%H:%M:%S`
#echo $timestr
echo "$timestr $1" >> $watcherLogFile
}
function error_log()
{
watcherLogFile=/usr/local/omc/log/cdr_data_proc_error`date +%Y%m%d`.log
timestr=`date +%H:%M:%S`
#echo $timestr
echo "$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}'`
cd $procdir
procfiles=`ls *.finish`
for file in $procfiles; do
datafile="`echo $file|awk -F. '{print $1}'`.dat"
if test -f $procdir/$datafile ; then
rm -rf error.txt
cat $procdir/$datafile | $mysqlbin -u$mysqluser -p$mysqlpwd 2>error.txt
if test -f error.txt ; then
if test `cat error.txt|wc -l` -gt 0 ; then
error_log "$datafile:`cat error.txt`"
fi
rm -rf error.txt
fi
rm -rf $procdir/$datafile $file
debug_log "Process $datafile"
fi
done
rm -rf $lockfile

98
bin/dual/cdr_io_proc.sh Normal file
View File

@@ -0,0 +1,98 @@
#!/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

Binary file not shown.

View File

@@ -0,0 +1,119 @@
#!/bin/bash
omcbinpath="/usr/local/omc/bin"
function debug_log()
{
watcherLogFile=/usr/local/omc/log/check_proc_status`date +%Y%m%d`.log
timestr=`date +%H:%M:%S`
#echo $timestr
echo "$timestr $1" >> $watcherLogFile
}
process_id=0
function get_process_id()
{
# parameter: process_name
progname=$1
process_id=`ps -aef|grep -v grep|grep '\./'$1 |awk '{print $2}'`
}
process_status=0
function get_process_status()
{
# parameter: process_name
progname=$1
pid=`ps -aef|grep -v grep|grep -c '\./'$1`
if test $progname == "mysqld" ; then
pid=`ps -aef|grep -v grep|grep -c 'mysqld'`
fi
if test $progname == "httpd" ; then
pid=`ps -aef|grep -v grep|grep -c 'httpd'`
fi
if test $pid -ge 1 ; then
process_status=1
else
process_status=0
fi
}
function get_param()
{
# parameter: file_name parameter_name
ret=`grep "$2=" $1|awk -F= '{print $2}'`
echo $ret
}
function get_master_process()
{
master_line=`grep -n '\[master_task\]' $omcbinpath/conf/server.conf |awk -F: '{print $1}'`
slave_line=`grep -n '\[slave_task\]' $omcbinpath/conf/server.conf |awk -F: '{print $1}'`
sed -n "${master_line},${slave_line}"p $omcbinpath/conf/server.conf|grep '^\s*[a-zA-Z]' |awk '{print $1}'
}
function get_slave_process()
{
slave_line=`grep -n '\[slave_task\]' $omcbinpath/conf/server.conf |awk -F: '{print $1}'`
sed -n "${slave_line},$"p $omcbinpath/conf/server.conf|grep '^\s*[a-zA-Z]' |awk '{print $1}'
}
omc_state=`get_param $omcbinpath/dual/dualstate State`
master_list=`get_master_process`
slave_list=`get_slave_process`
get_process_status "mysqld"
mysql_status=$process_status
get_process_status "httpd"
http_status=$process_status
get_process_status "omcMain"
omcMain_status=$process_status
status_list="$mysql_status$http_status$omcMain_status"
# master
if [ "x$omc_state" == "xMaster" -o "x$omc_state" == "xSingle" ] ;then
for prog in $master_list; do
get_process_status "$prog"
prog_status=$process_status
status_list="$status_list$prog_status"
if [ $prog_status -eq 0 ] ;then
debug_log "Run in $omc_state, start process $prog"
cd $omcbinpath
./$prog -d
sleep 1
fi
done
fi
# slave
if [ "x$omc_state" == "xSlave" ] ;then
for prog in $master_list; do
get_process_status "$prog"
if [ $process_status -eq 1 ] ;then
if [ `echo $slave_list|grep -c $prog` -eq 0 ] ;then
debug_log "Run in $omc_state, stop process $prog"
get_process_id $prog
kill -9 $process_id
fi
fi
done
for prog in $slave_list; do
get_process_status "$prog"
prog_status=$process_status
status_list="$status_list$prog_status"
if [ $prog_status -eq 0 ] ;then
debug_log "Run in $omc_state, start process $prog"
cd $omcbinpath
./$prog -d
sleep 1
fi
done
fi
echo $status_list
echo $status_list > $omcbinpath/dual/procstatus

1
bin/dual/dualstate Normal file
View File

@@ -0,0 +1 @@
State=Single

1
bin/dual/procstatus Normal file
View File

@@ -0,0 +1 @@
0001111111111111

38
bin/dual/sendfile Normal file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/expect
#This script interative with the remote server, and send the file to it
#This script have 6 parameters
#remoteip: the ip of the remote server
#username: the name for logining in
#userpass: the password for logining in
#resdir: the directory to store the files
#sendfile: the file to send to the remote server
#desdir: the directory to send the files
set remoteip [lindex $argv 0]
set username [lindex $argv 1]
set userpass [lindex $argv 2]
set resdir [lindex $argv 3]
set sendfile [lindex $argv 4]
set desdir [lindex $argv 5]
set resultfile [lindex $argv 6]
set sessionfile [lindex $argv 7]
set timeout 6
spawn sftp $username@$remoteip
expect "*(yes/no)?" {send "yes\n"; expect "*assword: "} timeout {exit 1} "*assword: "
send "$userpass\n"
expect "*sftp>*"
send "cd $desdir\n"
send "lcd $resdir\n"
send "put $sendfile\n"
expect "*100%*"
send "put $sessionfile\n"
expect "*100%*"
exec echo 1 > $resultfile
exit

View File

@@ -0,0 +1,7 @@
# Sync data source configuration
# NAME IO_PROC_SCRIPT DATA_PROC_SCRIPT SYNC_FILE_SIZE SEND_DIR RECV_DIR
CDR_SYNC,/usr/local/omc/bin/dual/cdr_io_proc.sh,/usr/local/omc/bin/dual/cdr_data_proc.sh,102400,/usr/local/omc/bin/dual/cdr_io_proc,/usr/local/omc/bin/dual/cdr_data_proc
# END