Hi,
I am trying to create a sript that will search the /etc/hosts file on my unix server for a host entry and output just the ip of that host to a file. Here is the script that I have created. Any help would be appreciated.
Thanks
#!/usr/local/bin/perl -w
system ( "pg /etc/hosts|grep LEX1|grep -v grep | awk '{ print $1 }' > /admin/script/install/printerip.out" );
sub readline
{
my($file) = @_;
my($line);
open(IN, $file) || die "Unable to open $file";
$line = <IN>;
close IN;
chomp($line);
return $line;
}
$ip = &readline("/admin/script/install/ipaddress.out");
$hostname = &readline("/admin/script/install/hostname.out");
$lex1 = &readline("/admin/script/install/printerip.out");
($a,$b,$c,$d) = split(/\./,$ip,4);
($storenum) = ($hostname =~ /bst00(\d\d\d)/);
$jd2 = $d + 7;
system( "/usr/sbin/hostent -c '$lex1' -i '$jd2'" );
I am trying to create a sript that will search the /etc/hosts file on my unix server for a host entry and output just the ip of that host to a file. Here is the script that I have created. Any help would be appreciated.
Thanks
#!/usr/local/bin/perl -w
system ( "pg /etc/hosts|grep LEX1|grep -v grep | awk '{ print $1 }' > /admin/script/install/printerip.out" );
sub readline
{
my($file) = @_;
my($line);
open(IN, $file) || die "Unable to open $file";
$line = <IN>;
close IN;
chomp($line);
return $line;
}
$ip = &readline("/admin/script/install/ipaddress.out");
$hostname = &readline("/admin/script/install/hostname.out");
$lex1 = &readline("/admin/script/install/printerip.out");
($a,$b,$c,$d) = split(/\./,$ip,4);
($storenum) = ($hostname =~ /bst00(\d\d\d)/);
$jd2 = $d + 7;
system( "/usr/sbin/hostent -c '$lex1' -i '$jd2'" );