大佬教程收集整理的这篇文章主要介绍了linux – 期待脚本等待命令挂起,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#! /bin/bash # this function runs a command like 'ssh' and provides the password function with_password { expect << END spawn $2 expect *assword:* send -- $1 interact wait END } # run "long_running_command" on the Remote Server with_password my_password "ssh my_user@some-server long_running_command" # rsync some data to the Remote Server with_password my_password "rsync /some/dir my_user@some-server:/remote/dir" # run some other random command with_password my_password "ssh my_user@some-server some_other_command"
问题是有时脚本会在等待生成命令时挂起.如果我
将wait命令退出expect脚本,命令将继续在远程上运行
服务器,但bash脚本将继续,我无法知道它何时完成.
为什么我的期望脚本似乎@L_772_6@挂起?
#! /bin/bash # this function runs a command like 'ssh' and provides the password function with_password { expect << END set timeout 900 spawn $2 expect *assword:* send -- $1 expect EOF END } # run "long_running_command" on the Remote Server with_password my_password "ssh my_user@some-server long_running_command" # rsync some data to the Remote Server with_password my_password "rsync /some/dir my_user@some-server:/remote/dir" # run some other random command with_password my_password "ssh my_user@some-server some_other_command"
当ssh / rsync命令在正确的时间(可能是?)关闭输入时,有时交互命令似乎有效,但它不可靠.
以上是大佬教程为你收集整理的linux – 期待脚本等待命令挂起全部内容,希望文章能够帮你解决linux – 期待脚本等待命令挂起所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。