< Concord
Content added Content deleted
imported>DrOwl (UpDate| added in "!split on " and changed var type for segment to $ from %) |
No edit summary |
||
Line 1:
this is a nice basic script that uses oracle's sql to get the element names that have a matching IP address.
*
#!/bin/perl
use strict;
use warnings;
# simple script that outputs the names of elements that have an IPaddress given as and argument
# added in a simple IP address test (NOTE this is not a full IPV4 test ie it will alow 333.x.x.x)
# usage 'getNamefromIP.pl x.x.x.x'▼
# but we wont worry about that as its only querying a database and will just retuirn no values
▲ # if not found. usage 'getNamefromIP.pl x.x.x.x'
my $oraPassword="password here";▼
my $
▲ my $oraPassword="password here";
my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress▼
my $oraPath="path to sqlplus command here"; # eg "/oracle/bin"
▲ my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress
my $elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF▼
set head off▼
if ($ipAddress !~ /^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/) {die "not a valid IPAddress";}
SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';▼
▲ my $elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF
exit▼
▲ set head off
EOF };▼
▲ SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';
▲ exit
foreach my $segment (split(/▼
▲ EOF };
next if /^$/;▼
▲ foreach my $segment (split(/ /,$elements)) {
next if /rows selected.$/;▼
▲ next if /^$/;
print "$segment ▼
▲ next if /rows selected.$/;
next if /rows selected/;
}
<nowiki>Insert non-formatted text here</nowiki><nowiki>Insert non-formatted text here</nowiki>
|
Revision as of 22:15, 3 February 2005
this is a nice basic script that uses oracle's sql to get the element names that have a matching IP address.
*# more getNamefromIP.pl #!/bin/perl use strict; use warnings; # simple script that outputs the names of elements that have an IPaddress given as and argument # added in a simple IP address test (NOTE this is not a full IPV4 test ie it will alow 333.x.x.x) # but we wont worry about that as its only querying a database and will just retuirn no values # if not found. usage 'getNamefromIP.pl x.x.x.x' my $oraUser="user name here"; my $oraPassword="password here"; my $oraPath="path to sqlplus command here"; # eg "/oracle/bin" my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress if ($ipAddress !~ /^(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})$/) {die "not a valid IPAddress";} my $elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF set head off SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress'; exit EOF }; foreach my $segment (split(/ /,$elements)) { next if /^$/; next if /rows selected.$/; next if /rows selected/; print "$segment"; }
Insert non-formatted text hereInsert non-formatted text here