【发布时间】:2019-05-21 11:52:51
【问题描述】:
之前我曾向question 询问过如何使用 SSH 确定远程站点中的路径是否为目录。如果路径不是目录,我希望创建目录。我尝试了两种方法来跟踪代码,但它似乎不起作用。感谢所有在这里提供帮助的人。
use File::Path;
my $destination_path = "<path>";
my $ssh = "usr/bin/ssh";
my $user_id = getpwuid( $< );
my $site = "<site_name>";
my $host = "rsync.$site.com";
if (system("$ssh $user_id\@$host [ -d $destination_path ]") == 0) {
print "It is a directory.\n";
} else {
print "It is not a directory.\n";
#First Way
if(system("$ssh $user_id\@$host [ make_path ($d_path_full) ]") == 0{
#Second Way
if(system("$ssh $user_id\@$host [ mkdir -p $d_path_full ]") == 0{
print "Create directory successfully.\n";
} else {
print "Create directory fail.\n";
}
}
【问题讨论】: