LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2008, 09:32 PM   #1
Speedy2k
LQ Newbie
 
Registered: Nov 2008
Posts: 9

Rep: Reputation: 0
gawk help needed.


Hi, i'm making right now a little perl script to connect to my LCDd server to display on an 20X4 LCD screen. I need to get my Local, External, and VPN ip adress.
I have found a script for the WAN one that is OK, but when i use my script to get the internal one, it seem to put a \n at the end, because i have a change line, so my lcd see the variable as a 2 line input and don't display it, i need to make it not put the last line change code. here is my internal ip script:

Code:
#!/bin/bash
if [ -z "$1" ]; then 
	echo usage: $0 interface
	exit
fi
IP=`/sbin/ifconfig $1 2> /dev/null|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`

if [ "$IP" == "" ]; then
	echo "none"
else
	echo "$IP"
fi
this is working fine, if i send this: getip.sh eth0, i received this.
i set this as a variable, but in the variable i don't want the line change.

Code:
root@pbx:/usr/src $ getip.sh eth0
72.0.206.19
root@pbx:/usr/src $
this script is my external ip script:

Code:
#/bin/bash
curl -s hxxp://www(dot)whatismyip(dot)com/automation/n09230945(dot)asp
and the output of this one is like that:
Code:
root@pbx:/usr/src $ getextip.sh
72.0.206.19root@pbx:/usr/src $

and this is what i need, is there a way to have the same output from my first script?? thanx a lot!
 
Old 11-06-2008, 01:39 AM   #2
rohit_k
LQ Newbie
 
Registered: Oct 2007
Location: Pune
Distribution: RHEL, SOLARIS, SUSE
Posts: 18

Rep: Reputation: 1
i guess variable $IP has no new line in it.
"echo" adds the new line on the screen.

please try 'echo -n xxx':
if [ "$IP" == "" ]; then
echo -n "none"
else
echo -n "$IP"
fi

HTH.

Rohit Kalsarpe
 
Old 11-07-2008, 11:10 AM   #3
Speedy2k
LQ Newbie
 
Registered: Nov 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Thanx a lot it have work!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gawk help.... visitnag Linux - Newbie 1 04-12-2008 12:55 PM
create a directory in gawk duparcmeur Linux - Newbie 6 04-03-2008 03:01 PM
where is curl and gawk ???????? bozart ROCK 11 10-23-2005 11:41 PM
gawk question luxpops Programming 1 09-12-2004 05:46 AM
FS=? in gawk realos Programming 2 05-28-2003 08:30 PM


All times are GMT -5. The time now is 04:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration