News:

So the widespread use of emojis these days kinda makes forum smileys pointless, yeah?

Main Menu

[SH] Display IP!

Started by Joe, October 27, 2005, 08:36:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Joe

wget -q http://www.javaop.com/~joe/ip.php
cat ip.php
rm ip.php
echo ' '


Could have written it yourself. Eat me. =).
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


iago

#1
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. 

Joe

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?
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Newby

wget -q thatwebpage &> /dev/null

Something along those lines.
- Newby
http://www.x86labs.org

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote from: Rule on June 30, 2008, 01:13:20 PM
Quote from: CrAz3D on June 30, 2008, 10:38:22 AM
I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Joe

#4
<3 newby.

EDIT -
Interestingly enough, it didn't work.
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


iago

Firstly, figure out which line is outputting the blank line.  Are you sure it's the wget?

Try

wget ... > /dev/null 2>&1

Joe

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
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


iago

When running your script, direct stdout (>) and stderr (2>) to /dev/null.  See which one gets rid of the blank line.