PracticeDev/study_clang/Mimic/Switch_DEMO/init.sh

167 lines
3.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#----------------------------------------------------------------------------------------------------------------------------------------------
#
# 1、 judgeMasterNos.py 先启动,以后台方式启动;
# 2、 judgeMasterNos.py启动以后sleep 2秒后再启动arpProxy.py同时通过ps命令查看arpProxy.py进程是否存在如果不存在将启动失败信息写入到当前目录下的log中
# 3、 arpProxy.py启动以后sleep 2秒后再启动icmpProxy.py同时通过ps命令查看icmpProxy.py进程是否存在如果不存在将启动失败信息写入到当前目录下的log中
# 4、 icmpProxy.py启动以后sleep 2秒后再启动udpProxy.py同时通过ps命令查看udpProxy.py进程是否存在如果不存在将启动失败信息写入到当前目录下的log中
# 5、 udpProxy.py启动以后sleep 2秒后再启动tcpProxy.py同时通过ps命令查看tcpProxy.py进程是否存在如果不存在将启动失败信息写入到当前目录下的log中
# 6、 判断arpProxy.py、icmpProxy.py、udpProxy.py、tcpProxy.py四个进程是否存在如果不存在将错误信息写入到log中。
#
#----------------------------------------------------------------------------------------------------------------------------------------------
#cmdpre="awk '/"
#cmdsuf="/' awk.temp"
log_mod="init_err" #用于分支不同的log格式
#在启动时的log记录
function log()
{
ERR_LOGFILE="error.log"
echo "[$pro] failed."
CUR_TIME=`date +'%Y-%m-%d %H-%M-%S'`
if [ -f $ERR_LOGFILE ];then
echo "[$pro] started failed at time $CUR_TIME" >> error.log;
fi
}
#在最后检查时的log记录
function log_check()
{
ERR_LOGFILE="error.log"
echo "[$pro] don't exist."
CUR_TIME=`date +'%Y-%m-%d %H-%M-%S'`
if [ -f $ERR_LOGFILE ];then
echo "[$pro] don't exist at time $CUR_TIME" >> error.log;
fi
}
#判断是否从ps中抓取到进程没有则调用log
function isNull()
{
if [ "$a" = "" ];then
if [ $log_mod = "init_err" ];then
log
else
log_check
fi
fi
}
#启动一个进程然后启动后抓取ps
function start()
{
sleep 2
echo "[$pro] init..."
if [ -f "${pro}.pyc" ];then
$s python ${pro}.pyc >/dev/null 2>&1 &
ps a > ps.temp
awk '{print $6}' 'ps.temp' > awk.temp
#cmd=${cmdpre}${pro}${cmdsuf} #尝试用连接的方法将awk组合命令但是会报错
fi
}
#'sudo' 命令前缀
s=''
# 1、
if [ -f "judgeMasterNos.pyc" ];then
$s nohup python judgeMasterNos.pyc >/dev/null 2>&1 &
fi
# 2、
pro="arpProxy"
start
a=`awk '/arpProxy/' 'awk.temp'` #因为命令中不能引用变量所以在这里分别写。
isNull
# 3、
pro="icmpProxy"
start
a=`awk '/icmpProxy/' 'awk.temp'`
isNull
# 4、
pro="udpProxy"
start
a=`awk '/udpProxy/' 'awk.temp'`
isNull
# 5、
pro="tcpProxy"
start
a=`awk '/tcpProxy/' 'awk.temp'`
isNull
pro="sshRelay"
start
a=`awk '/sshRelay/' 'awk.temp'`
isNull
pro="pro_mimic"
start
a=`awk '/pro_mimic/' 'awk.temp'`
isNull
pro="rip_mimic"
start
a=`awk '/rip_mimic/' 'awk.temp'`
isNull
# 6、
#改变log格式
log_mod="check"
ps a > ps.temp
awk '{print $6}' 'ps.temp' > awk.temp
pro="arpProxy"
a=`awk '/arpProxy/' 'awk.temp'`
isNull
# 6、
#改变log格式
log_mod="check"
ps a > ps.temp
awk '{print $6}' 'ps.temp' > awk.temp
pro="arpProxy"
a=`awk '/arpProxy/' 'awk.temp'`
isNull
pro="icmpProxy"
a=`awk '/icmpProxy/' 'awk.temp'`
isNull
pro="udpProxy"
a=`awk '/udpProxy/' 'awk.temp'`
isNull
pro="tcpProxy"
a=`awk '/tcpProxy/' 'awk.temp'`
isNull
pro="sshRelay"
a=`awk '/sshRelay/' 'awk.temp'`
isNull
pro="pro_mimic"
a=`awk '/pro_mimic/' 'awk.temp'`
isNull
pro="rip_mimic"
a=`awk '/rip_mimic/' 'awk.temp'`
isNull