我正在尝试根据远程服务器上文件的ctime,使用rsync从远程目录中rsync脚本中的文件进行rsync文件同步,但遇到了一些困难。
use strict;
use Net::OpenSSH;
my $user = "phil";
my $password = 'pass';
my $host = "xavier";
my $local_rules = "/etc/mail/rules.cf";
my $remote_rules = "/etc/mail/rules.cf";
my $keypath = "$userhome/.ssh/scp-key.key";
my $ssh = Net::OpenSSH->new($host, user => $user, passphrase => $password, key_path => $keypath);
$ssh->rsync_get({exclude => '*~', archive => 1, safe_links => 1, verbose => 1,
files_from => "<(find /var/spool/dir/quarantine -cnewer /home/phil/last-run -type f -exec basename {} \\;)>"}, '/var/spool/dir/quarantine/','/home/phil/quarantine/');在执行时,它会失败,如下所示:
rsync: failed to open files-from file <(find /var/spool/dir/quarantine -cnewer /home/phil/last-run -type f -exec basename {} \;)>: No such file or directory
rsync error: syntax or usage error (code 1) at main.c(1765) [client=3.2.4]当我在远程服务器上手动执行find命令时,它会生成一个文件列表。
我知道查找是在远程主机上执行的,但可能不是这样吗?
我遗漏了什么?有更好的方法吗?
发布于 2022-07-21 21:43:54
在将参数files_from传递给rsync_get()命令行之前,将引用参数ssh。引用阻止Shell识别"<(find /var/spool/dir/quarantine -cnewer /home/phil/last-run -type f -exec basename {} \\;)"中的元字符。请向问题跟踪器报告并征求意见。
作为解决办法,您可以预先创建files_from文件:
use File::Temp qw(tempfile);
my ($fh, $tempfile) = tempfile();
my $res = system "find /var/spool/dir/quarantine -cnewer /home/phil/last-run -type f -exec basename {} \\; > $tempfile";
die "find command failed" if $res != 0;然后,像这样运行rsync_get():
$ssh->rsync_get(
{
exclude => '*~',
archive => 1,
safe_links => 1,
verbose => 1,
files_from => $tempfile
},
'/var/spool/dir/quarantine/',
'/home/phil/quarantine/'
);编辑
要从远程获取文件列表,可以尝试
use feature qw(say);
use File::Temp qw(tempfile);
my @files = $ssh->capture("find /var/spool/dir/quarantine -cnewer /home/phil/last-run -type f -exec basename {} \\;") or
die "remote command failed: " . $ssh->error;
my ($fh, $tempfile) = tempfile();
say $fh $_ for @files;
close $fh;https://stackoverflow.com/questions/73059537
复制相似问题