Advertisement

update script

Started by October 27, 2004 08:09 PM
5 comments, last by Lambo429 20 years ago
So i have this shell script that updates my ip everytime it changes but i need some help. THis is what i got: #!/bin/bash wget --http-user= --http-passwd= http://192.168.1.1/st_poe.html printf "GET http://dynamic.registerfly.com/index.php?domain=domain.com&password=mypassword&ipaddress=xxx.xxx.xxx.xxx&host=ICQ&sdd=Save+changes HTTP/1.0\n\n" | nc dynamic.registerfly.com 80 What i need to do is be able to extract the ip from st_poe.html which is saved in the same directory as my script. I then need to be able to put that ip into the printf statement. Im not to good at shell scripting, i had a killer perl script that did this but perl aint working. Any help would be appreciated. Lambo
We all think that we are the best with computers but we all keep reffering to the same all-mighty all-knowing Guru, Google.
take a look at sed and regular expressions.
Advertisement
Yeah, sed could make you life easier. Supposing that the line in st_poe.html might look something like this:

myIP = 192.168.100.100

you may use this:

grep myIP ./st_poe.html | sed -e '/s/myIP =//' .

However, I'm not sure how it should be done, if the ip was inserted into html probably. Maybe just put it trough 2 sed's?!


[Edited by - j0seph on November 1, 2004 7:32:02 PM]
Okay,theres two lines in st_poe.htm that im looking at. They are:
<td background="bar_bg.jpg" width="47%"> IP Address:</td>
<td bgcolor="white">69.177.144.44</td></tr>
Some how i need to extract the address into a variable that can then be put into a printf "GET http://dynamic.registerfly.com/index.php?ip=$variable
Lambo
We all think that we are the best with computers but we all keep reffering to the same all-mighty all-knowing Guru, Google.
If anyone wants to know how i did it:
#!/bin/bash
rm /root/Desktop/st_poe.htm
wget --http-user=me --http-passwd=1234 http://192.168.1.1/st_poe.htm
ipold="$(cat /root/Desktop/ip.txt)"
ipraw="$(sed -n '97p' st_poe.htm)"
ipmorebetter="${ipraw%</td></tr>}"
ipgood="${ipmorebetter:20}"
echo $ipgood
echo $ipold
if [ "$ipold" != "$ipgood" ]
then
printf "GET http://dynamic.registerfly.com/index.php?domain=domain.com&password=password&ipaddress="$ipgood"&host=www&sdd=Save+Changes HTTP/1.0\n\n" | nc dynamic.registerfly.com 80
printf "GET http://dynamic.registerfly.com/index.php?domain=domain.com&password=password&ipaddress="$ipgood"&host=@&sdd=Save+Changes HTTP/1.0\n\n" | nc dynamic.registerfly.com 80
fi
echo $ipgood > /root/Desktop/ip.txt
This shoudl work with a linksys router but may need to be tweaked a little. Keep in mind the web address of the update page of your dns service may be different.
Lambo
We all think that we are the best with computers but we all keep reffering to the same all-mighty all-knowing Guru, Google.
very nice.
Advertisement
You like? I was very proud of myself. Im going to refine it because i dont think it needs to be that long.
Lambo
We all think that we are the best with computers but we all keep reffering to the same all-mighty all-knowing Guru, Google.

This topic is closed to new replies.

Advertisement