测试后,逻辑通过验证的代码:
BEEF_PID=1 MITM_PID=1 LOG_PID=1 TESTING(){ if [ $1 -eq 0 ];then echo "SUCCESS" else echo "ERROR" fi } PID_STATUS(){ if [ ! -n "$1" ];then echo "is_NULL" return 45 else echo "not_NULL" return 0 fi } PID_STATUS $MITM_PID num=$? if [ $num -eq 0 ];then echo "already" else ls TESTING $? fi
待修改的脚本
MITM_PID=$(pgrep -f mitm) GET_PID=$(pgrep -f getmac) LOG_PID=$(pgrep -f logprocessing) TESTING(){ PID_STATUS=$1 if [ $PID_STATUS -eq 0 ];then echo "SUCCESS" else echo "ERROR" exit 1 fi } # #if [ ! -n "$MITM_PID" ];then # echo "is NULL"; #else # echo "not NULL"; #fi for i in {"$MITM_PID","$GET_PID","$LOG_PID"} do if [ ! -n "$i" ];then echo "is NULL"; else echo "not NULL"; fi done case $1 in start) #echo $1 #ruby /usr/share/beef-xss/beef -v #true TESTING $? #mitmdump -s /usr/share/beef-xss/mitm.py -m transparent #true /bin/sh /root/22.sh TESTING $? #python3 /home/code/logprocessing.py #true /bin/sh /root/33.sh TESTING $? ;; stop) #echo $1 #kill -9 ${BEEF_PID} true TESTING $? #kill -9 ${MITM_PID} true TESTING $? #kill -9 ${LOG_PID} true TESTING $? ;; reload) echo $1 ;; *) echo "USAGE:$0{start|stop|reload}" esac
for i in {"$MITM_PID","$GET_PID","$LOG_PID"} do if [ ! -n "$i" ];then echo "is NULL"; else echo "not NULL"; fi done