下面的“for”循环在同一服务器上本地运行。
但是,当通过远程服务器上的“ssh”协议触发时,不会收到输出。
请问,任何人都可以建议如何使其在远程服务器上触发时工作。
for i in $(cat Server_List) # Works
do # Works
echo $i # Works
ssh $i '$(for a in `/usr/sbin/lspath|grep scsi|awk '{print \$2}'|sort|uniq`; # Doesn't Work
do # Doesn't Work
echo "\$a `/usr/sbin/lspath |awk '/'\$a' /' |uniq|awk '/Enabled/'|wc -l`;done)' # Doesn't Work
done # Works
答案1
您可以尝试heredoc
通过 ssh 运行多行命令:
ssh user@host <<'EOC'
for a in $(/usr/sbin/lspath | awk '/scsi/ {print $2}'| sort -u); do
# do something
done
EOC