脚本宝典收集整理的这篇文章主要介绍了expect spawn报错invalid command name,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
在编写shell脚本中,使用免交互方式spawn追踪进程报错
/usr/bin/expect <<EOF cd /opt/redis-5.0.7/utils spawn ./install_server.sh exPEct "instance: [6379]" {send "r"} expect "[/etc/redis/6379.conf]" {send "r"} expect "[/VAR/LOG/redis_6379.log]" {send "r"} expect "[/var/lib/redis/6379]" {send "r"} expect "path []" {send "/usr/local/redis/bin/redis-server"} expect eof EOF
查找原因,并尝试分解各个步骤
最后发现,是expect里面的内容中的括号【】有问题,不能使用[],将其去除即可执行了,或者使用 -ex {},把语句放到大括号中即可
send中也是如此,也不可用[],需要转义或者使用send -- {}格式,将send的内容放到大括号中转义
修改后的脚本
yum -y install expect &> /dev/null /usr/bin/expect <<EOF cd /opt/redis-5.0.7/utils spawn /opt/redis-5.0.7/utils/install_server.sh expect "instance:" {send "r"} expect "/etc/redis/6379.conf" {send "r"} expect "/var/log/redis_6379.log" {send "r"} expect "/var/lib/redis/6379" {send "r"} expect "path" {send "/usr/local/redis/bin/redis-serverr"} expect "ENTER" {send "r"} expect eof EOF
以上是脚本宝典为你收集整理的expect spawn报错invalid command name全部内容,希望文章能够帮你解决expect spawn报错invalid command name所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。