Clan x86
Technical (Development, Security, etc.) => General Programming => Topic started by: Joe on October 27, 2005, 08:36:40 pm
-
wget -q http://www.javaop.com/~joe/ip.php
cat ip.php
rm ip.php
echo ' '
Could have written it yourself. Eat me. =).
-
I actually set up a script to do that based on a website. Hmm, wonder if I still have it..
yep!
IP=`curl -s www.whatismyip.com | grep -i "<title" | cut -d\ -f 5`
<edit> by the way, you might want to do some error handling in yours"
if wget -q http://www.javaop.com/~joe/ip.php; then
cat ip.php
rm ip.php
echo ' '
else
echo "Failed to retrieve ip..."
fi
that's untested, but it should work.
or
wget -q http://www.javaop.com/~joe/ip.php
if [ -f ip.php ]; then
cat ip.php
rm ip.php
echo ' '
else
echo "Failed"
fi
Again, untested :)
Also, I would recommend using a temporary file, like /tmp/ip.php.
-
I stuck this in /usr/bin, so now in JavaOp I can just do /run getip. Problem though, wget outputs a single blank line, so it shows as
#1:
#1: IP
I do wget -q so it doesn't output anything, but it still outputs that line. Anykne know how to stop that?
-
wget -q thatwebpage &> /dev/null
Something along those lines.
-
<3 newby.
EDIT -
Interestingly enough, it didn't work.
-
Firstly, figure out which line is outputting the blank line. Are you sure it's the wget?
Try
wget ... > /dev/null 2>&1
-
Unless cat is outputting a blank line (which it doesn't, from my experience with it), it has to be wget, because cat outputs the IP on the second line, and wget is the only thing before it.
@code: /test
EDIT -
Wow.
joe@JoeMomma:~/dev/java/rps $ getip
172.129.223.201
-
When running your script, direct stdout (>) and stderr (2>) to /dev/null. See which one gets rid of the blank line.