FreeKB - Perl SSH run command on a remote host
Perl - SSH run command on a remote host

The following Perl script can be used to execute a command on a remote host.

#!/usr/bin/perl
use Core;

my $user = "username";
my $pass = "password";
my $host = "hostname of the target server";
my $command = "the command you want to run on the target server";


($stdout, $stderr, $exit) = create_shell($host, $user, $pass);
($stdout, $stderr, $exit) = execute_shell_inline($host, $user, $command);
     

 

If you want to prompt a user for input, make sure to use chomp.

my $user = <STDIN>;
chomp($user);

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 41836 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |