shell两个变量调用方法

[root@VM_163_107 /data/script/shell]# cat listen_monitor.sh
#!/bin/sh
#set -x
pid1=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QWorld`
pid2=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QDBProxy`
pid3=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QGameServer`
pid4=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QGateway`
pid5=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QCommunity`
DC_PATH=/usr/local/services/CloudDCAgent_L5-1.0/alarm
for i in {1..5}
do
        a=pid
        eval pidname="$"$a$i
        #echo $pidname
        if [ -z pid$i ]
        then
                $DC_PATH/cloud_alarm 100697808 "the rpgserver is down" -o rpgserver
                echo $pidname "The process of death, to save it,now"
        else
                echo "everything is ok" >/dev/null 2>&1
fi
done

使用eval进行两个变量同时调用

a=pid
eval b="$"$a$i
echo $b


第二种调用方式

for i in $pid{1..5}

$i =pid1 pid2 pid3 pid4 pid5
#!/bin/sh
#set -x
pid1=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QWorld`
pid2=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QDBProxy`
pid3=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QGameServer`
pid4=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QGateway`
pid5=`ps -ef|grep QD|grep -v grep |awk '{print $14}'|grep QCommunity`
DC_PATH=/usr/local/services/CloudDCAgent_L5-1.0/alarm
for i in $pid{1..5}
do
        echo $i
done
~


淘宝小店-运维学习参考资料

http://shop62632578.taobao.com




你可能感兴趣的:(shell)