I think the problem comes from this line:
Code: Select all
export pf2=`echo $(/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_$sysinfo $HOSTNAME | grep "Active" | awk '{print "\47" $1 "\47, "}') | sed 's/,*$//'`
I've tried this:
Code: Select all
if [ "$LS" == "physical" ]; then
echo "test123"
# Get BGP status
[color=#FF0000]/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_$sysinfo $HOSTNAME | grep "Active" | awk '{print "\47" $1 "\47, "}' | sed 's/,*$//'[/color]
[color=#FF0000]export pf2=`echo $(/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_$sysinfo $HOSTNAME | grep "Active" | awk '{print "\47" $1 "\47, "}') | sed 's/,*$//'`[/color]
pf=`/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_$sysinfo $HOSTNAME | grep "Active" | awk '{print "\47" $1 "\47, "}' | sed 's/,*$//'`
export test=$pf
echo "$pf " > /tmp/bgp.$HOSTNAME.$LS.log
#pf2="'202.40.160.151' , '202.40.160.152' , '2001:7fa:0:1::ca28:a13b', '2001:7fa:0:1::ca28:a195'";
# pf2=`cat /tmp/bgp_$HOSTNAME'_'$LS.log`
# pf3=`echo $(/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_$sysinfo $HOSTNAME $LS | grep Active | awk '{print "\47" $1 "\47, "}')`
# pfmy=`echo $(/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_$sysinfo $HOSTNAME | grep Active | awk '{print "\47" $1 "\47, "}') | sed 's/,*$//'`
echo "test1 $pf2 ???";
#cat /tmp/bgp.$HOSTNAME.$LS.log
else
pf2=`echo $(/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_ls_$sysinfo $HOSTNAME $LS | grep "Active"| awk '{print "\47" $1 "\47, "}' ) | sed 's/,*$//'`
sudo echo "$pf2 " > /tmp/bgp.$HOSTNAME.$LS.log
# pfmy=`echo $(/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_ls_$sysinfo $HOSTNAME $LS | grep 'Active' | awk '{print "\47" $1 "\47, "}') | sed 's/,*$//'`
#echo "456...."
fi
....
The red line is added for debugging, and it give no result. It looks like a permission relative or something wrong in my
expect script.
Here is the different ways I ran the script:
The first: gave me unexpected result ( wrong result)
Code: Select all
[root@monitor-network libexec]# su - nagios -c "/usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_Juniper 119.18.185.2"
spawn ssh -i /home/nagios/.ssh/monitor_rsa digicom_noc@119.18.185.2
--- JUNOS 11.4R7.5 built 2013-03-01 11:57:40 UTC
{master}
digicom_noc@IGW-HK> ... AS | except inet | except Peer |[root@monitor-network libexec]#
The second:, run the script with nagios account, this gave me the expected result
Code: Select all
[nagios@monitor-network libexec]$ /usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_Juniper 119.18.185.2
spawn ssh -i /home/nagios/.ssh/monitor_rsa digicom_noc@119.18.185.2
--- JUNOS 11.4R7.5 built 2013-03-01 11:57:40 UTC
{master}
digicom_noc@IGW-HK> show bgp summary | find AS | except inet | except Peer | no-more
72.14.223.30 15169 500528 511527 0 2 23w6d5h 184/303/303/0 0/0/0/0
119.18.185.1 38726 22340 3147989 0 12 1w0d0h 184/277/277/0 0/0/0/0
119.18.185.61 38726 195139 235335 0 2 6w4d10h 94/94/94/0 0/0/0/0
and the third, run the script with root account, the same result with the second way.
Code: Select all
[root@monitor-network libexec]# /usr/bin/expect /usr/local/nagios/libexec/plugins/get_bgp_Juniper 119.18.185.2
So, do you have any suggestions for this?