LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2001, 04:41 PM   #1
yank_
LQ Newbie
 
Registered: Jan 2001
Posts: 21

Rep: Reputation: 15

Is there some way I can use my ip address in a bash program. My ip address changes, as I am conencted to a DHCP cable modem. I wish to write a script that uses the ip address in it, but i can not just put xxx.xxx.xxx.xxx because the x's change when I restart the computer. I also need to know how to designate wich network card im using because the comp has two net cards.

is there a command like +eth0ip or +eth1ip that i can substitute for [ip of eth0] or [ip of eth1]

Please let me know.. im new to this linux stuff.
 
Old 02-16-2001, 12:45 PM   #2
devnull
Member
 
Registered: Feb 2001
Posts: 84

Rep: Reputation: 15
Hi,

first do a "ifconfig -a". Then you will see, what cards are active (look for UP....RUNNING...).

In a shell-script you can do the following:

eth0=`ifconfig eth0 | grep 'inet addr'| awk '{print $2}'|sed -e "s/addr\://"`

Watch out for the ticks and back-ticks!!

Hope it will help you.
 
Old 02-16-2001, 03:20 PM   #3
yank_
LQ Newbie
 
Registered: Jan 2001
Posts: 21

Original Poster
Rep: Reputation: 15
either this didnt work, or im not sure exactly what it is suppose to do

Please tell me the script to do the following

echo ipaddress (where ipaddress is the not known ip)

in a half-life server, i have to tell it what the ip is

./hlds_run +ip xxx.xxx.xxx.xxx (where xxx... is the ip addresss)

what would put for xxx.xxx.xxx.xxx if i dont know what the ip is because its different every time the script is run.
 
Old 02-16-2001, 03:32 PM   #4
yank_
LQ Newbie
 
Registered: Jan 2001
Posts: 21

Original Poster
Rep: Reputation: 15
ok, i got that to work..

now how do you allow the use of ifconfig over telnet?
it says command not found
but when i run it directly from that computer.. it works fine.

Thanks for the help
 
Old 02-16-2001, 04:02 PM   #5
devnull
Member
 
Registered: Feb 2001
Posts: 84

Rep: Reputation: 15
i have just tested it (haven't done it while writing it) and it works fine.
type it in a shell and then do an "echo eth0".
It will show you the ip-address of the interface eth0!

step by step:
with "eth0=...." you define a variable (your current ip-address). You can call it also ipaddress or something else.
"ifconfig eth0" will get all infos of the interface eth0 (or eth1 eth2 ...). These infos are piped " | " to "grep". grep cuts out the "inet addr"-part from the ifconfig-command.
This part is then handed over to "awk" who is responsible for sorting out the second part (..print $2) of the the grep results. this will result in something like "...addr:192.168.xxx.xxx:".
You can't work with this, so this part is piped to "sed".
sed now is doing some filtering and the result is the pure ip-address of the interface you want to know!

i don't know that half-life game, but if you start it with "hlds_run", you can now just add the name of the vairable (eth0 or ipaddress or whatever you've called it).

Have you done shell-scripting before or do you want to start it by hand?

btw: i think you can't copy and paste the command-line i have written because the shell might interpret the pipe-sign ( | ) al the letter "l". And that will never work ;-)
 
Old 02-16-2001, 06:40 PM   #6
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,602

Rep: Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084Reputation: 4084
/sbin is probably not in your path. Either type /sbin/ifconfig or add /sbin to your path.
 
  


Reply



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
variable $- swan2925 Linux - Software 1 07-20-2005 01:51 AM
bash, how to get variable name from variable Duudson Programming 6 01-06-2005 04:38 PM
Variable in variable-name Ephracis Programming 1 11-17-2004 11:38 AM
calling a variable within a variable sdandeker Programming 9 04-28-2004 03:55 PM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 03:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:25 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
Open Source Consulting | Domain Registration