×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Concord/GetNamefromIP: Difference between revisions

    Content added Content deleted
    imported>mutante
    m (despam)
    imported>DrOwl
    (UpDate| added in "!split on " and changed var type for segment to $ from %)
    Line 14: Line 14:
    my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress
    my $ipAddress=$ARGV[0] || die "Missing args $!"; # get ipAddress


    my %elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF
    my $elements = qx{$oraPath/sqlplus -S $oraUser/$oraPassword <<EOF
    set head off
    set head off
    SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';
    SELECT NAME from NH_ELEMENT where IP_ADDRESS='$ipAddress';
    Line 20: Line 20:
    EOF };
    EOF };


    foreach (%elements) {
    foreach my $segment (split(/
    /,$elements)) {
    next if /^
    next if /^$/;
    /;
    next if /rows selected.$/;
    next if /rows selected.$/;
    print $_;
    print "$segment
    ";
    }</pre>
    }</pre>

    Revision as of 12:09, 13 January 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
    1. !/bin/perl

    use strict; use warnings;

    1. simple script that outputs the names of elements that have an IPaddress given as and argument
    2. 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

    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.$/;
     print "$segment 
    

    ";

    }

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.