LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Tough script (https://www.linuxquestions.org/questions/linux-newbie-8/tough-script-696085/)

makuyl 01-13-2009 06:26 PM

If you have a router/nat you can just grep for 192.168 or which ever of the four natted adress spaces you use.
Without nat, your isp probably has the same first two octets every time, so grep for what you usually have.

jschiwal 01-13-2009 06:55 PM

You could use "getent hosts <hostname>" as well. Even if you use avahi for name resolution. You will still get the localhost IP address for the host you are running on since that is what is in the hosts file.

The freemem value might be useless. There will be memory used for cache that will be freed if the system needs it. Obtaining the load and memory values from a remote host, you probably need to have some kind of client running on those hosts or use ssh to run a command or script that will return the values. And running a client or script to monitor memory and load value will of course reduce the available memory and increase the load. As you would expect.

I find it convenient to use public key encryption for ssh. Using that and "AllowHosts" makes it more secure, I you don't need to deal with using expect to deal with authentication. Sometimes that can interfere with pipes and tees in your script. Having usernames and passwords in scripts is best to avoid as well.

mmahulo 01-14-2009 03:19 AM

Quote:

Originally Posted by GazL (Post 3405989)
IP=$(hostname -i)

may save you all that messing with ifconfig and sed to pull the ip address out.

Thanks Gazyl

That was fairly easy.

GazL 01-14-2009 07:05 AM

Quote:

Originally Posted by colucix (Post 3406281)
Unless there is a way to know which is the external interface and which is (are) the internal one(s), other than check the address itself after its extraction, of course. Moreover, there are a lot of different types of network interface. For example having my system at home connected via DSL modem and running OpenSuse I have
Code:

dsl0      Link encap:Point-to-Point Protocol
eth0      Link encap:Ethernet
lo        Link encap:Local Loopback
wlan0    Link encap:Ethernet
wmaster0  Link encap:UNSPEC


In the absense of an external reference such as dns, the simplest solution I could come up with would be to assume the interface associated with the default route is the correct one,
Code:

ifconfig $(route | grep default | awk '{print $8}')
And then parse that with the sed script you provided in your responses above. It's still not entirely foolproof, but at least you're not hard coding the interface name which is a step in the right direction.

Ofcourse, if the system is configured such that hostname -i returns the correct value, it avoids the need for all this shenanigans, but as you made clear, this cannot be relied upon on all distributions and setups.


This is why I enjoy hanging out on LQ. You can often find interesting insights in threads that you expect to be pretty straightforward on first viewing. Yes... I know, I'm Sad like that. ;)

GazL 01-14-2009 07:07 AM

Quote:

Originally Posted by mmahulo (Post 3408053)
Thanks Gazyl

That was fairly easy.

You're welcome. Just keep in mind the issue that Colucix and I were discussing.

colucix 01-14-2009 07:15 AM

Quote:

Originally Posted by GazL (Post 3408230)
In the absense of an external reference such as dns, the simplest solution I could come up with would be to assume the interface associated with the default route is the correct one

This is a great advice! Well done!
Quote:

Originally Posted by GazL (Post 3408230)
This is why I enjoy hanging out on LQ. You can often find interesting insights in threads that you expect to be pretty straightforward on first viewing.

Totally agree! :)

slack12ware 02-07-2009 02:38 AM

Quote:

Originally Posted by chrism01 (Post 3405343)
@slack12ware:

~ = tilde

` = backquote

ohps my bad, youre right there, was in a bit of a hurry.


All times are GMT -5. The time now is 07:27 AM.