开发者

How to do remote execution in standard perl 5.10.0

I want to run some commands via a remote program. I've tried it using following code.

my $promt = '/bash\$ $/';    
use Net::Telnet ();

$conn = new Net::Telnet (Timeout => 10, Prompt => $promt);
$conn->open($host);
$conn->login($username, $pa开发者_开发百科sswd);
@lines = $conn->cmd("who");
print @lines;

But it gives error, Can't locate Net/Telnet.pm in @INC.....

Is there way to do this task without changing, adding standard perl 5.10.0 modules?


Just install the Net::Telnet perl module in your own user path. OR if you are not bound to perl, the best way i can suggest to run commands on remote systems is SSH.

$ssh user@ip 'command'

This will give you the results in STDOUT.

Examples:

root@www:~ # ssh root@www 'who'
brock pts/0 Oct 21 10:31 (75.72.194.149)
jim pts/1 Oct 25 06:25 (128.101.163.128)

You can find few more at "Run Remote Command with SSH".


Ive solved the problem using this function...

# Get the needed values from the database
sub Execute_Remote_Command($) {
    print "sshpass -p $password ssh $user\@$host '$_[0]'\n";
    print `sshpass -p $password ssh $user\@$host '$_[0]'`;
    print `exit`;
}

Function -Execute_Remote_Command- needed a parameter which needed to be run in the remote machine.

The only additional requirement needed here is supporting sshpass command and it can be downloaded using following url. http://linux.softpedia.com/get/Security/Sshpass-8693.shtml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜