1

I have list of ip addresses in one txt file which I have named ip.txt

I want to call those ip in my .sh file, I am not sure how to proceed here..

here I did soemthing

#!/bin/bash -x
var='ip.txt'
for i in $var; do
echo snmpwalk -v 2c -c rcgoips $i 1.3.6.1.3.83.1.4.5.0
done

Please tell me how to do that?

4

1 回答 1

4

这应该使它:

#!/bin/bash -x
var='ip.txt'
while read line; do
  echo snmpwalk -v 2c -c rcgoips $line 1.3.6.1.3.83.1.4.5.0
done < $var

for像你一样使用

#!/bin/bash -x
var='ip.txt'
for line in $(<$var); do
  echo snmpwalk -v 2c -c rcgoips $line 1.3.6.1.3.83.1.4.5.0
done

因为语法是:for i in $(<file); do echo $i; done

于 2013-08-09T14:08:48.963 回答