我正在使用pssh在远程服务器上运行脚本。对于linux,我没有遇到问题,但是对于solaris,我在运行脚本时遇到了问题。
我正在使用shebang来使用bash shell,它使用的是sh shell,这导致了这个问题。
# cat test.sh
#!/usr/bin/env bash
UNAME=$(uname)
if [ $UNAME = SunOS ]; then
echo SunOS
fi
# ssh host1 'bash -s' <test.sh
SunOS
# pssh -H host1 -i -I <test.sh
[1] 04:15:47 [FAILURE] host1 Exited with error code 2
Stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.
-sh: syntax error: `UNAME=$' unexpected
# 发布于 2015-10-28 20:04:25
Linux和Solaris都会忽略只有在运行可执行文件时才处理的shebang,而不是在读取stdin时处理的shebang。碰巧Linux sh实际上是bash,所以支持您使用的语法。
更简单的解决方法是修复脚本,使其可移植到任何shell:
UNAME=`uname`
if [ "$UNAME" = SunOS ]; then
echo SunOS
fi或者,您可以将远程用户的默认外壳更改为更标准的外壳,如ksh或bash。
https://stackoverflow.com/questions/33389606
复制相似问题