I have edited my .bashrc to look like this with some help from others on this forum ... Thanks guys for the help on the weather segment of this script...
An issue I have ran into is the code for the external ip address. If for some reason the site I use to check the external IP doesn't respond .. it locks up my bash at that point until it gets the information.
What I would like to do is change it so that I can have it so if it doesn't respond in a second or 500ms .. then to just move on so it doesn't hang. I hope that makes sense .. here is the code I'm using for it.
localnet()
{
declare -a INETARRAY
INETARRAY=( `/sbin/ifconfig | awk /'inet addr/ {print $2}' && /sbin/ifconfig | awk /'Bcast/ {print $3}'`)
echo -ne ${INETARRAY[@]} "ExtIP:" ; myip
}
myip ()
{
lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | grep "Current IP Address" | cut -d":" -f2 | cut -d" " -f2
}
Basically I need an if statement that would do something like this:
if the site doesn't give whats expected withing a configurable amount of time load "line 1" else load "line 2"
Line 1 would contain the code without the external IP request Line 2 would contain the code with the external IP request.
Now .. I'm not actually sure what is causing the hang .. I don't know if the site is not responding .. or if it is busy and taking longer to respond or if its getting information but not whats expected ... it happens sporadically and if it hangs on me I can close the shell and open it and usually it will get the information .. I thought about ping but ... again .. not sure if the site would still respond to the ping but not produce what the script is looking for and still hang.
I just don't know how to set up the statement correctly to make this happen or something similar
Thanks in advanced.
I tried the line suggested by glenn jackman
curl --silent --output - --connect-timeout 2 --max-time 3 http://checkip.dyndns.org:8245/ | grep "Current IP Address" | cut -d":" -f2 | cut -d"" -f2
It did get the IP address but the resulted in this:
xxx.xxx.xxx.xxx</body></html>
I will have to probably adjust the second cut command .. lol .. guess I need to learn cut :D
If i use
curl --silent --output - --connect-timeout 2 --max-time 3 http://checkip.dyndns.org:8245/ | grep "Current IP Address"
I get the output of:
<html><head><title>Current IP Check</title></head><body>Current IP Address: xxx.xxx.xxx.xxx</body></html>
If I switch back to the lynx line instead of curl and use the -read_timeout=1 -connect-timeout=1
this does keep the shell from hanging if it has connections issues but .. it produces errors which was why I was hoping to make some sort of if statement
Network: addr:192.168.1.20 addr:127.0.0.1 Bcast:192.168.1.255 ExtIP:
Looking up checkip.dyndns.org:8245
Making HTTP connection to checkip.dyndns.org:8245
Alert!: Connection failed (too many retries).
Alert!: Unable to connect to remote host.
lynx: Can't access startfile http://checkip.dyndns.org:8245/
curl --silent --output - --connect-timeout 2 --max-time 3 $URL
-read_timeout
and-connect_timeout
- try setting thosecurl --silent --output - --connect-timeout 2 --max-time 3 icanhazip.com
?