Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: Joe on October 27, 2005, 08:36:40 pm

Title: [SH] Display IP!
Post by: Joe on October 27, 2005, 08:36:40 pm
Code: [Select]
wget -q http://www.javaop.com/~joe/ip.php
cat ip.php
rm ip.php
echo ' '

Could have written it yourself. Eat me. =).
Title: Re: [SH] Display IP!
Post by: iago on October 27, 2005, 08:58:40 pm
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"

Code: [Select]
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

Code: [Select]
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. 
Title: Re: [SH] Display IP!
Post by: Joe on October 27, 2005, 10:59:28 pm
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?
Title: Re: [SH] Display IP!
Post by: Newby on October 27, 2005, 11:13:45 pm
wget -q thatwebpage &> /dev/null

Something along those lines.
Title: Re: [SH] Display IP!
Post by: Joe on October 27, 2005, 11:26:33 pm
<3 newby.

EDIT -
Interestingly enough, it didn't work.
Title: Re: [SH] Display IP!
Post by: iago on October 28, 2005, 08:43:36 am
Firstly, figure out which line is outputting the blank line.  Are you sure it's the wget?

Try

wget ... > /dev/null 2>&1
Title: Re: [SH] Display IP!
Post by: Joe on November 04, 2005, 05:08:22 pm
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.
Code: [Select]
joe@JoeMomma:~/dev/java/rps $ getip

172.129.223.201
Title: Re: [SH] Display IP!
Post by: iago on November 04, 2005, 05:54:47 pm
When running your script, direct stdout (>) and stderr (2>) to /dev/null.  See which one gets rid of the blank line.