$ssh 是 Net::SSH::Expect 对象。场景就像,从我的本地机器我需要 ssh 到测试服务器。从测试服务器我可以 ssh 到其他被测服务器并执行命令。所以 $ssh 句柄用于测试服务器。现在从测试服务器我正在对其他机器执行 ssh 并执行 mkexport。
while($no_of_exports)
{
my $share_name = &get_share_name();
my $path="$fs" . "$share_name";
$cmd="ssh mgmt001st001 mkexport $share_name $path --nfs \"*\\(rw,no_root_squash\\)\"";
print "CMD: $cmd";
$out=$ssh->exec("$cmd");
print $out;
--$no_of_exports;
}
Output :
[root@ganesha36 ~]#
CMD: ssh mgmt001st001 mkexport kas142818597 /ibm/gpfs0/kas142818597 --nfs "*\(rw,no_root_squash\)"
97 --nfs "*\(rw,no_rxport kas142818597 /ibm/gpfs0/kas1428185
perl 脚本的命令执行失败但是当我从命令行运行相同的命令时它通过了:以下是我直接从测试服务器执行的相同命令。
[root@ganesha36 ~]# ssh mgmt001st001 mkexport kas327134640 /ibm/gpfs0/kas327134640 --nfs "*\(rw,no_root_squash\)"
EFSSG0019I The export kas327134640 has been successfully created.
EFSSG1000I 命令成功完成。
以下是脚本中的行:
$cmd='ssh mgmt001st001 mkexport ' . $share_name . ' ' . $path . ' --nfs \'' . '\\*' . '\\(rw,no_root_squash\\)\'';
print "CMD: $cmd";
$out=$ssh->exec("$cmd");
print $out;
这是输出:
CMD: ssh mgmt001st001 mkexport kas522199075 /ibm/gpfs0/kas522199075 --nfs '\*\(rw,no_root_squash\)'
75 --nfs '\*\(rw,no_xport kas522199075 /ibm/gpfs0/kas5221990
> root_squash\)'
EFSSF1156A An error occurred in NFS configuration. The client syntax cannot be parsed. See "man exports" for help. Cause: *(rw,no_
bash: line 1: root_squash): command not found
我已将 * 更改为客户端名称工作正常...但是 * 有什么问题
$cmd='ssh mgmt001st001 mkexport ' . $share_name . ' ' . $path . ' --nfs "' . 'client002' . '\\\\(rw,no_root_squash\\)"';
print "CMD: $cmd";
$out=$ssh->exec("$cmd");
print $out;
CMD: ssh mgmt001st001 mkexport kas482978105 /ibm/gpfs0/kas482978105 --nfs "client002\\(rw,no_root_squash\)"
05 --nfs "client002\xport kas482978105 /ibm/gpfs0/kas4829781
> \(rw,no_root_squash\)"
EFSSG0019I The export kas482978105 has been successfully created.
EFSSG1000I The command completed successfully.