needhelp has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I am still having no luck in setting the output I get from a DIG on a remote server. Have a look, here is what I have so far:
#!/use/bin/perl use strict; print "Domain? "; my $domain = <STDIN>; chop($domain); Use Net::SSH qw(issh); my $user= "<USERNAME>"; my $host= "<HOSTNAME>"; my $cmd="dig +short $domain"; issh("$user\@$host", "$cmd");
..That part of the code opens up the SSH session and performs the command "dig +short (on whatever domain is specified)." The "dig" prints out an IP address, that is what I need. I need to a way to set that to a variable, and so far I am having no luck. Any help with this would be much appreciated. Thank you.... John

Replies are listed 'Best First'.
Re: Set a variable to remote information
by sauoq (Abbot) on Jul 02, 2003 at 15:41 UTC

    First, your "use" is capitalized. That won't work.

    A quick look at the docs for Net::SSH suggests you probably need to use sshopen2() or sshopen3() rather than issh().

    If this is all you are doing though, you might get by with something much more simple like:

    my $dig_output = `ssh $user\@$host $cmd`;

    -sauoq
    "My two cents aren't worth a dime.";
    
      Sorry about the "use", that was just a mistype. But anyways, I have tried the:
      my $dig_output = issh("$user\@$host", "$cmd")
      ..and it prints out a zero??? And I would use sshopen2() or sshopen3() but all I need to do is perform the one command. Also, if I use those I will have to setup access keys, which would be quite tedious for my finished program.. By the way, your 2 cents are quite helpful.... And sorry about the chop/chomp, I'm very new to perl, just trying to write something to make my life a little easier.. Thanks
        But anyways, I have tried the:
        my $dig_output = issh("$user\@$host", "$cmd")
        ..and it prints out a zero???

        Uhm... where did you get that from? It wasn't what I suggested... ;-)

        My suggestion was to forego the use of Net::SSH and just use a qx() or backticks instead. Since all you want is the output from the one command, that might prove to be much easier.

        -sauoq
        "My two cents aren't worth a dime.";
        
Re: Set a variable to remote information
by Zaxo (Archbishop) on Jul 02, 2003 at 15:52 UTC

    Not what you asked, but line 8, chop($domain); is not what you should do. chomp is better, chomp( my $domain = <STDIN>); will replace lines 7 and 8.

    After Compline,
    Zaxo