在bash脚本中使用here文档运行多个命令时出错

时间:2012-10-31 16:00:50

标签: bash shell unix ssh sed

我正在尝试使用数组在3个远程服务器中执行以下命令集,使用Here Document,但收到错误

代码 -

ssh -oPasswordAuthentication=no $remoteUser@${SERVER[i]} <<-END_TEXT
VALUE=`cat /home/cognos/cognos/c8/configuration/cogstartup.xml | grep -i xsd:long | head -1 | cut -d">" -f2 | sed 's/[:/<|crn:value]*//g'`
VALUE_BACKUP=$VALUE
........................ (many more lines of code)
RESULT1=`perl -e '@stats = stat("/home/cognos/cognos/c8/configuration/signkeypair"); print ((time - $stats[9]) < '$VALUE');'`

END_TEXT

错误:

**error -**
syntax error at -e line 1, near "< )"
Execution of -e aborted due to compilation errors.
syntax error at -e line 1, near "< )"
Execution of -e aborted due to compilation errors.
syntax error at -e line 1, near "< )"
Execution of -e aborted due to compilation errors.

ps-使用scp将命令复制到远程服务器,然后使用ssh运行它们不是我正在寻找的解决方案。

1 个答案:

答案 0 :(得分:2)

查看整个此处的文档并搜索-e

修改

将END_TEXT括在单引号中,如下所示:

ssh ... <<-'END_TEXT'
...
END_TEXT

这将阻止$ VALUE替换为空字符串,然后才能在远程服务器上使用。