在ssh连接上使用命令sed和echo

时间:2014-05-20 21:42:33

标签: linux bash ssh

我知道有人已经要求类似的东西,但我还没能在远程主机中使用这些命令。我有bash:

#!/bin/bash
IMSI="732111030120252"
ssh openbts@192.168.10.12 bash -c " '
sed -i '61,$d' /etc/asterisk/sip.conf   #erase the lines fron 61 to end of the file sip.conf
sed -i '288,$d' /etc/asterisk/extensions.conf
echo "[IMSI$IMSI].(sets)" >> /home/openbts/Desktop/Prueba  #Write that expression inside Prueba (Ignore .)

' "

但是,他正在考虑$d()类似本地变量,而不是像sed和echo命令的一部分。

我发现你可以使用\\\$d或回声中的所有行,但它们不起作用。

任何人都有想法?谢谢

1 个答案:

答案 0 :(得分:0)

您需要正确转义字符串,尤其是$"

ssh openbts@192.168.10.12 "sed -i '61,\$d' /etc/asterisk/sip.conf;
  sed -i '288,\$d' /etc/asterisk/extensions.conf;
  echo \"[IMSI\$IMSI].(sets)\" >> /home/openbts/Desktop/Prueba;"