I created bash script wich works as Nagios plugin. Here is a part of it:
44 CURDUPLEX=`ethtool $IFACE|grep "Duplex"|cut -d ':' -f 2|xargs`
45 CURSPEED=`ethtool $IFACE|grep "Speed"|cut -d ':' -f 2|xargs|sed 's/.\{4\}$//'`
46
47 if [ $CURSPEED -eq $SPEED ]; then
48 if [ $CURDUPLEX = $DUPLEX ]; then
49 echo "OK: Interface $IFACE link at ${CURSPEED}Mb\s and $CURDUPLEX duplex."
50 exit $OK
51 else
52 echo "CRITICAL: Interface $IFACE link at ${CURSPEED}Mb\s [OK] and $CURDUPLEX duplex (Expected $DUPLEX)."
53 exit $CRIT
54 fi
55 elif [ $CURDUPLEX = $DUPLEX ]; then
56 echo "CRITICAL: Interface $IFACE link at ${CURSPEED}Mb\s and $CURDUPLEX duplex [OK]."
57 exit $CRIT
58 else
59 echo "CRITICAL: Interface $IFACE link at ${CURSPEED}Mb\s and $CURDUPLEX duplex (Expected $DUPLEX)."
60 exit $CRIT
61 fi
62 }
When I run it I see the error:
]# ./check_physlink usage
./check_physlink: line 48: syntax error near unexpected token `then'
./check_physlink: line 48: ` if [ $CURDUPLEX = $DUPLEX ]; then'
I think about for an hour yet, and cannot to understand what is wrong. Thought about no space between left bracket and dollar sign, but no as you see.
Please advise. Thank you.