How to write a script to covert string to numeric

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
haiyanzi1212
Posts: 2
Joined: Tue Jul 09, 2013 4:22 am

How to write a script to covert string to numeric

Post by haiyanzi1212 »

I need to monitor the network tunnel status,the value is "ACTIVE" "DOWN" "CRASHED",so i need to convert it to numeric。
I wrote a .sh script,it should display "1",but it display "0"

my script:
networktunnel.sh
#!/bin/shdf
status=$(snmpwalk -v 2c -c $snmpcommunity $hostname $OID | awk -F':' '{print $NF}' | awk -F'"' '{print $2}')
case $status in
ACTIVE) print "1"
;;
DOWN) print "2"
;;
CRASHED) print "3"
;;
esac

Data input Method configuration :
Data Input Methods:networktunnel
Input Type:Script/Command
Input String:<path_cacti>/scripts/test.sh <snmpcom><host><OID>
Input Fields:snmpcom、host、OID
output:Status
Attachments
display
display
2013-07-09_181053.jpg (37.89 KiB) Viewed 673 times
configuration
configuration
2013-07-09_180431.jpg (109.22 KiB) Viewed 673 times
haiyanzi1212
Posts: 2
Joined: Tue Jul 09, 2013 4:22 am

Re: How to write a script to covert string to numeric

Post by haiyanzi1212 »

I had solved this problem.
script:
#!/bin/shdf
snmpcom=$1
hostname=$2
OID=$3
status=$(snmpwalk -v 2c -c $snmpcom $hostname $OID | awk -F':' '{print $NF}' | awk -F'"' '{print $2}')
case $status in
ACTIVE) No=1
print "status:$No"
;;
DOWN) No=2
print "status:$No"
;;
CRASHED) No=3
print "status:$No"
;;
esac
congiuration:
Attachments
my configuration
my configuration
2013-07-10_174319.jpg (98.85 KiB) Viewed 656 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest