The script
#! /bin/ksh
#
set -x
n=0
snmpwalk -c xxxxx yyyyy system | while IFS=read line
do
arrayname[$n]=$line
n=$(( $n + 1 ))
echo $(arrayname[0])
done
The a portion of the output w/set -x enabled
+ n=0
+ snmpwalk -c tmedomain4 192.168.63.247 system
+ line
+ IFS=read
sysDescr.0 = STRING: Cisco IOS Software, 3800 Software (C3845-ADVIPSERVICESK9-M), Version 12.4(3b), RELEASE SOFTWARE (fc3)
+ arrayname[0]=
+ n=1
+ arrayname[0]
ter[9]: arrayname[0]: not found
+ echo
+ line
+ IFS=read
Technical Support: + arrayname[1]=
+ n=2
+ arrayname[0]
ter[9]: arrayname[0]: not found
+ echo
I need to learn how to use arrays. It would make my life alot easier. But I just cant see what Im doing wrong here.
I want to put the contents of the snmp response into an array, then be able to print or assign its value to a variable.
SunOS xxxxx 5.8 Generic_108528-15 sun4u sparc SUNW,UltraSPARC-IIi-cEngine and running the script in KSH.
Can someone show me the light ?
Thanks
#! /bin/ksh
#
set -x
n=0
snmpwalk -c xxxxx yyyyy system | while IFS=read line
do
arrayname[$n]=$line
n=$(( $n + 1 ))
echo $(arrayname[0])
done
The a portion of the output w/set -x enabled
+ n=0
+ snmpwalk -c tmedomain4 192.168.63.247 system
+ line
+ IFS=read
sysDescr.0 = STRING: Cisco IOS Software, 3800 Software (C3845-ADVIPSERVICESK9-M), Version 12.4(3b), RELEASE SOFTWARE (fc3)
+ arrayname[0]=
+ n=1
+ arrayname[0]
ter[9]: arrayname[0]: not found
+ echo
+ line
+ IFS=read
Technical Support: + arrayname[1]=
+ n=2
+ arrayname[0]
ter[9]: arrayname[0]: not found
+ echo
I need to learn how to use arrays. It would make my life alot easier. But I just cant see what Im doing wrong here.
I want to put the contents of the snmp response into an array, then be able to print or assign its value to a variable.
SunOS xxxxx 5.8 Generic_108528-15 sun4u sparc SUNW,UltraSPARC-IIi-cEngine and running the script in KSH.
Can someone show me the light ?
Thanks