reading a file from remote host using perl

痴心易碎 提交于 2019-12-30 12:25:12

问题


I am trying to read a file(temp.txt) placed under /root directory on remote host(ubuntu) in same LAN from ubuntu machine.(ssh and ftp are open) The perl script is able to connect and a OpenSSH dialog box appears asking for password and then program exists.Please anybody helps..below is my script.

use POSIX qw(strftime);
use strict;
use warnings;


use File::Remote;
 my $remote = new File::Remote;

# Standard filehandles
$remote->open(FILE, ">>X.X.X.X:/root/temp.txt") or die $!;
print FILE "Here's a line that's added.\n";
$remote->close(FILE);

i get the below error when executed.

Bareword "FILE" not allowed while "strict subs" in use at /root/Desktop/test.pl line 10.
Bareword "FILE" not allowed while "strict subs" in use at /root/Desktop/test.pl line 12.
Execution of /root/Desktop/test.pl aborted due to compilation errors.

回答1:


You must install sh open keys to be able to access X.X.X.X without a password.

$ ssh-keygen
$ ssh-copy-id -i ~/.ssh/id_rsa.pub X.X.X.X

Than you can try to access the host with ssh:

$ ssh X.X.X.X 

And add please something like

local *FILE;

at the beginning of the file to get rid of these warnings about bareword.



来源:https://stackoverflow.com/questions/11135588/reading-a-file-from-remote-host-using-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!