shell expect 没有执行预期的命令?

shell 命令如下,目的是在本地合并master代码到master_release分支,然后ssh到远程主机上,执行一个git pull命令。

 cd '/Users/yanwushu/Documents/code/php/erp'

 echo  '----------------------------------> 【切换到 master 分支 】'
 git checkout master
 git pull

 echo  '----------------------------------> 【切换到 master_release 分支】'
 git checkout master_release
 git pull

 echo  '----------------------------------> 【将 master 合并 到 master_release】'
 git merge master
 git push


/usr/bin/expect << eof
set timeout 30
spawn ssh root@xxx.xxx.xxx.xxx
expect "root@*"  {send "cd /www/wwwroot/oa.xx.com/ \r"}
expect "root@*"  {send "git pull \r"}
expect "root@*"  {send "exit \r"}
eof
echo done!

执行日志如下:

spawn ssh root@xxx.xxx.xxx.xxx
Last failed login: Sat Feb 18 15:09:23 CST 2023 from xxx.xxx.xxx.xxx on ssh:notty
There were 4564 failed login attempts since the last successful login.
Last login: Fri Feb 17 19:19:25 2023 from xxx.xxx.xxx.xxx
Welcome to  ALIYUN Cloud Server!
[root@localhost ~]# cd /www/wwwroot/oa.xxx.com/ 
[root@localhost oa.xxx.com]# done!
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[进程已完成]

可见,git pull 命令没有执行,但是重新执行一遍脚本,发现git pull命令又执行了,日志如下:

spawn ssh root@xxx.xxx.xxx.xxx
Last login: Sat Feb 18 15:09:59 2023 from xxx.xxx.xxx.xxx
Welcome to  ALIYUN Cloud Server!
[root@localhost ~]# cd /www/wwwroot/oa.xxx.com/ 
[root@localhost oa.xxx.com]# git pull 
xxxxx git pull 部分日志忽略
[root@localhost oa.xxx.com]# done!
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[进程已完成]

请问为何第一次执行时git pull命令没有执行呢?

阅读 1.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进