我知道有人已经要求类似的东西,但我无法在远程主机中使用该命令。我有狂欢:
#!/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
或 echo 内的所有线路,但它们不起作用。
有人有想法吗?谢谢
最佳答案
您需要正确转义字符串,尤其是 $
和 "
:
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;"
关于linux - 通过 ssh 连接使用命令 sed 和 echo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23770471/