extraction of hostnames in hostfile

G

grk

Hi Guru's,

If i have file /hosts and then inside it

10.10.0.1 host1.new.corp.com
10.20.0.1 rts.new.corp.com

say i wan to extract only

host1.new.corp.com
rts.new.corp.com

two hostnames check if alive with ping and then run a rsh command to
check if df of these two machines are >90% or not, how best i can
achive this.

i have script which actually makes use of a file which i actually
prepare by going to hosts file and then updating very often. so if i
can get it direclty from hosts file and do that would save a lot fo
time.
thx for perl gurus in advance.

grk
 
J

Josef Moellers

grk said:
Hi Guru's,

If i have file /hosts and then inside it

10.10.0.1 host1.new.corp.com
10.20.0.1 rts.new.corp.com

say i wan to extract only

host1.new.corp.com
rts.new.corp.com

two hostnames check if alive with ping and then run a rsh command to
check if df of these two machines are >90% or not, how best i can
achive this.

i have script which actually makes use of a file which i actually
prepare by going to hosts file and then updating very often. so if i
can get it direclty from hosts file and do that would save a lot fo
time.

So: what have you tried so far and where did it not work?
From your description, it is not very clear what exactly your problem
is, so: post some code and we can be of help.
 
T

Tad McClellan

grk said:
If i have file /hosts and then inside it

10.10.0.1 host1.new.corp.com
10.20.0.1 rts.new.corp.com

say i wan to extract only

host1.new.corp.com
rts.new.corp.com


perl -lane 'print $F[1]' /hosts

two hostnames check if alive with ping and then run a rsh command to
check if df of these two machines are >90% or not, how best i can
achive this.


There are 3 ways of executing external programs, described in
the answer to this Perl FAQ:


How can I capture STDERR from an external command?
 
T

Tintin

grk said:
Hi Guru's,

If i have file /hosts and then inside it

10.10.0.1 host1.new.corp.com
10.20.0.1 rts.new.corp.com

say i wan to extract only

host1.new.corp.com
rts.new.corp.com

two hostnames check if alive with ping and then run a rsh command to
check if df of these two machines are >90% or not, how best i can
achive this.

i have script which actually makes use of a file which i actually
prepare by going to hosts file and then updating very often. so if i
can get it direclty from hosts file and do that would save a lot fo
time.
thx for perl gurus in advance.

Much better job for a shell script

#!/bin/sh
for host in `awk '{print $2}' /etc/hosts`
do
if ping -c1 $host >/dev/null 2>&1
then
df=`rsh $host df /whateverfilesystem | tail -1 | awk '{print $5}' |
sed 's/%//'`
if [ $df -gt 90 ]
then
echo "filesystem greater than 90% capacity"
fi
fi
done

Note that ping and df options will vary depending on your Unix flavour.

Of course, you could write the equivalent in Perl, but you'd either have to
use a number of modules, or use a whole bunch of system calls, which would
pretty much defeat the purpose of writing it in Perl in the first place.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top