Answer the question
In order to leave comments, you need to log in
Why doesn't the bash wget command work if the variable is taken from a file?
Good afternoon.
Just discovering the world of scripts.
I want to automate getting information from a large number of pages.
I am using the wget utility.
Everything works if I create a user variable:
for ip in 10.0.0.1 10.0.0.2 etc.
The task is to take the IP addresses (written in a column) from the hosts.txt file through the command
wget -qO- http://admin:[email protected]$ip/System |grep model.
#!/bin/bash
file="hosts.txt"
for ip in 10.0.0.1 10.0.0.2
do
echo "Device on ip address $ip"
wget -qO- http://admin:[email protected]$ip/System |grep model
done
#!/bin/bash
file="hosts.txt"
for ip in $(cat $file)
do
echo "Model for ip address $ip"
wget -qO- http://admin:[email protected]$ip/System |grep model
done
Answer the question
In order to leave comments, you need to log in
In echo, change $var to $ip, otherwise it's somehow illogical.
Before grep, put a pipe, that is, a vertical dash: |
And the rest - the code is quite working.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question