I am trying to write my own dynamic DNS client to check my router's external IP address and upload it somewhere where I can find it. Here's the simplified script scrapeip:
Code:
#!/bin/bash
while read -r line
do
echo Trying to scrape IP from: $line
$line > scrapedip.txt
if [ $? -eq 0 ]; then
echo success # ...and do something useful
break
fi
echo fail
done < ipscrapers.txt
The script reads a file ipscrapers.txt, line by line, and tries to execute each line. If one succeeds it breaks the loop. For now I only have one line in ipscrapers.txt:
Code:
wget -qO- http://checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
When I run this script I get:
Quote:
[email protected]:~/scripts$ ./scrapeip
Trying to scrape IP from: wget -qO-
http://checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
wget: Invalid --execute command ‘'s/.*Current’
fail
[email protected]:~/scripts$
When I run the wget line at the command line it works fine, also if I have it directly in the script it works. It does not work when I read the command line from a file. How can I fix this?
The point of all this is to eventually have a longer list of scrapees, and then rotate the list after every use round-robin style, spreading the load overs many servers.