我想在ssh命令中传递一个字符串变量。你可以在下面的代码中看到,我ssh到一个服务器,然后cd到一个目录,我传递了一个变量。(cd $orig)变量是从我读入的一个文件中提取出来的,并放入一个数组中。我想这就是我的错误所在,因为在我使用split命令从文件读入后,可能有不需要的隐藏字符。
下面是我得到的错误:
ksh:/OnSight/jetplan/脚本/发布/jscripts^M:无法打开perl脚本“AddAlias.pl“:没有这样的文件或目录/OnSight/users/onsadm SSHing到densbp 53/OnSight//scripts/release/jscripts
它找不到我的脚本,因为CD到文件夹失败。
有时错误会说找不到“文件结尾”。就像我在执行带有EOF隐藏符号的CD命令一样。
代码如下:
for(my $j=0; $j < $#servName+1; $j++)
{
print "\nSSHing to $servName[$j]\n\n";
my $orig = $scriptfileLoc[$j];
#my $chopped = chop($orig);
chop($orig);
chomp($orig);
print ("\n$orig\n");
$sshstart = `ssh $servName[$j] "cd $orig; pwd; perl AddAlias.pl $aliasName $aliasCommand $addperl $servProfileLoc[$j]"`;
print $sshstart;
}
它输出$orig变量,在chop和chomp之后它看起来很好。(我已经自己做了,仍然得到同样的错误)所以我在SSH命令中传递它,它不工作。
我有一个服务器文件,保存所有的服务器信息,是的,它看起来重复我知道。
densbp40:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp41:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp42:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp43:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp50:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp51:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp52:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp53:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp60:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp61:/export/home/.profile:/OnSight/scripts/release/jscripts
densbp62:/export/home/.profile:/OnSight/scripts/release/jscripts
tulsbp40:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp41:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp42:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp43:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp50:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp51:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp52:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
tulsbp53:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
densbcp1:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
densbcp2:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
densmsv1:/OnSight/.profile:/OnSight/scripts/jscripts
denamdp1:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
denamap1:/OnSight/users/profile:/OnSight/scripts/release/jscripts
denamap2:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
denfpev1:/OnSight/users/.profile:/OnSight/scripts/release/jscripts
此脚本要求用户选择是将文件发送到所有服务器还是仅发送到一个服务器。
1条答案
按热度按时间kxeu7u2r1#
“^M”是回车符,也称为“\r”。请使用正则表达式删除它: