Operating System - HP-UX
1755233 Members
7027 Online
108831 Solutions
New Discussion юеВ

Re: read values from a text file.

 
Soul_1
Respected Contributor

read values from a text file.

Hi all,

I need to customize the script
##################
clear
echo "Enter IP or x to quit > \c"
while read ip
do
[ "${ip}" = "x" ] && exit 0
/opt/OV/bin/snmpwalk -c test ${ip}|more
echo "Enter IP or x to quit > \c"
done
##########################
In this script i need to press x and enter the ip address.Instead of that i need to read the ipaddress from a text file and execute the command.

Thanks in advance.
Th
6 REPLIES 6
Patrick Wallek
Honored Contributor

Re: read values from a text file.

Do this:

while read ip
do
[ "${ip}" = "x" ] && exit 0
/opt/OV/bin/snmpwalk -c test ${ip}|more
echo "Enter IP or x to quit > \c"
done < ip_addr_file
Dennis Handly
Acclaimed Contributor

Re: read values from a text file.

>Patrick: Do this:

Since you are reading from a file, there is probably no need for the check for "x" and the echo:
while read ip; do
/opt/OV/bin/snmpwalk -c test ${ip} | more
done < ip_addr_file
Soul_1
Respected Contributor

Re: read values from a text file.

Hi all,

Thanks for the response,

Its working fine.Please take this example.I want to redirect the err to one file and normal; o/p to another.
################################
clear
while read ip; do
/usr/sbin/ping ${ip} -n 3 $2>pingerr|tee $1>output
done < /tmp/ipfile
####################################
please correct this if i went wrong some where.b'coz am not getting the file updated .i.e pingerr and output.

Thanks in advance
Steven Schweda
Honored Contributor

Re: read values from a text file.

> [...] $2>pingerr|tee $1>output

Do you mean "2>" and "1>"?

man
Dennis Handly
Acclaimed Contributor

Re: read values from a text file.

>am not getting the file updated. i.e. pingerr and output.

You probably need to append:
while read ip; do
/usr/sbin/ping ${ip} -n 3 2>> pingerr | tee -a output
done < /tmp/ipfile
Arturo Galbiati
Esteemed Contributor

Re: read values from a text file.

Hello,
preparare a file with the listf of IPs and x at the end:
255.255.1.2
255.255.1.3
x

run your script (without changing it!!!) using the file created:

your_script
No changes to your script, no need to retest it. (you can countinue to use it in interactive mode as before)
first priciple of the programmers:
never touch working script!

HTH,
Art