Click to See Complete Forum and Search --> : variables and $eth0_address
TobyR
04-25-2004, 03:43 AM
From reading HOWTO docs (and in particular Snort configutaion info) it seems to me there should be variables called $eth0_address, $eth1_address etc. However, if I run a straight ...
echo $eth0_address
... then I get a null response, plus if I try to ise it in context it doesn't work. I know 'env' and 'printenv' give a list of all the environment variables, but is there a way to list other variables (such as this '$eth0_address')?
Any ideas? I'm running RH7.3, kernel 2.4.20.
Thanks
Toby
TobyR
04-25-2004, 05:14 AM
Mmm, just realised this went into the wrong forum to post this in - if any moderator can/wants to put this in a more appropriate forum then I'd be grateful.
Thanks
mdwatts
04-25-2004, 11:15 AM
Moved to the Networking forum. $5 please :)
I would imagine not ALL distros would use those variables. SuSE doesn't.
Are you just looking for the assigned ip address for eth0?
ifconfig eth0
TobyR
04-25-2004, 11:23 AM
Canadian, US or other? ;-)
I'm probaly showing my ignorance here, but from the IP addres shown in 'ifconfig eth0' how can I then refer to the IP address as a variable in a script?
Thanks in advance.
bwkaz
04-25-2004, 03:04 PM
/sbin/ifconfig eth0 | grep inet | cut -d: -f2 | cut -d' ' -f1 (that is, ifconfig eth0, search for the string "inet" and print out only that line, then break that line apart using : as a separator, and print only the second field, then break that field apart using space as a separator and print only the first field) will print out just the IP address. Now to get that into a variable, you put it in between $( and ), like so:
youripaddress=$(/sbin/ifconfig eth0 | grep inet | cut -d: -f2 | cut -d' ' -f1) If you're not using bash, then you'll probably have to replace $( and ) with backticks (the unshifted tilde key on a US keyboard), but $( and ) will work if you're using bash (they also nest more easily).
TobyR
04-25-2004, 06:45 PM
Many thanks
Toby
justlinux.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.