Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: [Help]Build a tool/application using Perl

by daxim (Curate)
on Oct 10, 2019 at 08:10 UTC ( #11107284=note: print w/replies, xml ) Need Help??


in reply to [Help]Build a tool/application using Perl

ssh to a server then issuing commands [Ö] issue "date" - get outputs and push them into a variable @tmp
Net::SSH::Any seems easiest to me.
#!/usr/bin/env perl use Net::SSH::Any qw(); my $ssh = Net::SSH::Any->new('192.168.1.10', user => 'root', password +=> '123456'); my @tmp = $ssh->capture('date');
How to build an application?
Perhaps Module::Build::Tiny? You need to explain what you want to achieve because "build" can mean different things.

Simple Perl programs do not require a building step, they can be run as-is.

Replies are listed 'Best First'.
Re^2: [Help]Build a tool/application using Perl
by tctoa (Novice) on Oct 10, 2019 at 09:22 UTC
    Thank you daxim,

    Look like this does not work.

    use Net::SSH::Any qw(); my $ssh = Net::SSH::Any->new( '172.20.251.20', user => 'root', password => 'r3 +v3nue' ); my @tmp = $ssh->capture('ls -lrt'); print " @tmp";

    Output:

     Use of uninitialized value $tmp[0] in join or string at test.pl line 7.

    For the application, please be explained again. I try to give an simple example to easier: - Using Perl to have a script to detect an even number from a number input from keyboar - Create an application base on this script. This can be installed on Windowns. Then, when I wannna find I only need to run the app instead of executing perl "script.pl" I am sorry, I cannot use exactly works to describe.

      I only need to run the app instead of executing perl "script.pl"
      That's called "compile to a standalone executable". See pp or staticperl or perlcc.

      It's easier to just associate the .pl file extension, so when you attempt to run a .pl file (for example by double-clicking in a file manager), it executes Perl automatically. When you use the Strawberry Perl installer, it does that association for you already.

      Consider adding error handling, as documented in Net::SSH::Any:

      my @tmp = $ssh->capture('ls -lrt'); $ssh->error and die "'ls -lrt' failed: " . $ssh->error;

        Thanks Corion, It works fine on Linux platform, and not work on Windowns for SSH But everytime I issue $ssh->capture($cmd), I need to input password again. my code:

        use strict; use warnings; use Net::SSH::Any qw(); my $ssh = Net::SSH::Any->new( '172.21.71.197', user => 'root', password => 'r3 +v3nue' ); my @tmp = $ssh->capture('ls -lrt'); print "@tmp \n"; print "====================\n"; @tmp = $ssh->capture('date'); foreach (@tmp) { if ( $_ =~ /(\d+:\d+:\d+)/ ) { print "Time is $1"; last; } }
        Output:
        root@svr1087# perl test.pl root@172.21.71.197's password: total 88 -r-xr-xr-x. 1 root root 332 Apr 22 2015 patchC3iptablesCustom.sh -r-xr-xr-x. 1 root root 508 Apr 23 2015 jre1.6.sh dr-xr-xr-x. 2 root root 4096 Nov 8 2018 Adax -rw-r--r--. 1 root root 1807 Jul 19 17:55 preinstall.log -rw-r--r--. 1 root root 6782 Jul 19 17:58 install.log.syslog -rw-r--r--. 1 root root 25057 Jul 19 18:00 install.log -rw-------. 1 root root 10302 Jul 19 18:00 anaconda-ks.cfg -rw-r--r--. 1 root root 14788 Jul 19 18:03 postinstall.log -rw-r--r-- 1 root root 4 Jul 22 14:11 hung_task_timeout_secs~ ==================== root@172.21.71.197's password: Time is 05:06:39# + + + root@svr1087#

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11107284]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2020-09-25 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (137 votes). Check out past polls.

    Notices?