当前位置: 首页 > news >正文

网站建设合作流程图装饰公司起名字寓意好的字

网站建设合作流程图,装饰公司起名字寓意好的字,网站建设维护方案,义县城乡建设局网站expect 是什么 expect - programmed dialogue with interactive programs#xff08;与互动程序进行程序对话#xff09; 定义脚本执行的 shell #!/usr/bin/expect -f 定义的是执行 expect 可执行文件的链接路径#xff08;或真实路径#xff09;#xff0c;功能类似于bas…expect 是什么 expect - programmed dialogue with interactive programs与互动程序进行程序对话 定义脚本执行的 shell #!/usr/bin/expect -f 定义的是执行 expect 可执行文件的链接路径或真实路径功能类似于bash等shell功能。 set timeout 10 设置超时时间单位是秒如果设为 timeout -1表示永远不超时。 spawn spawn 进入 expect 环境后才能执行内部命令不能直接在默认的 shell 环境种进行执行 主要功能传递交互指令 expect 主要判断输出结果是否包含某项字符串如果没有设置超时时间则立即返回如果设置了超时时间则等待一段时间后返回。 send 执行交互动作就是想要执行的命令。 命令字符串结尾要加上“\r”如果出现异常等待的状态可以进行核查。 interact 执行完后保持交互状态把控制权交给控制台如果不添加这一项交互命令会自动推出。 exp_continue The command exp_continue allows expect itself to continue executing rather than returning as it normally would. By default exp_continue resets the timeout timer. The -continue_timer flag prevents timer from being restarted. (See expect for more information.) 命令exp_continue允许expect 重复执行而不是直接返回。默认情况下exp_continue重置超时计时器。-continue_timer 标志阻止计时器重新启动。 $argv expect 脚本可以接受从bash传递过来的参数可以使用 [lindex $argv n]获得n从0开始分别表示第1个到第n个参数。 eof The pattern eof introduces an action that is executed upon end-of-file. A separate eof pattern may also follow the output flag in which case it is matched if an eof is detected while writing output. The default eof action is “return”, so that interact simply returns upon any EOF. 希望实现场景 ssh 到目标主机后检查目标文件夹是否存在如果存在先删除后创建如果不存在则创建。退出ssh交互界面使用scp将本地zip文件上传到目标主机。ssh 到目标主机后解压zip文件到指定目录。 # 首次连接目标主机需要输入yes rootcurtis-Aspire-E5-471G:/home/curtis/write_code# ssh 192.168.0.101 The authenticity of host 192.168.0.101 (192.168.0.101) cant be established. ECDSA key fingerprint is SHA256:gsW8dLII4nP2kSburZz0NKi6yR4A3SnrEJVFsAw0. Are you sure you want to continue connecting (yes/no/[fingerprint])?# 需要输入密码的提示 rootcurtis-Aspire-E5-471G:/home/curtis/write_code# ./func.exp rlk 192.168.0.101 123 spawn ssh rlk192.168.0.101 rlk192.168.0.101s password:按照下下边这种写法会发现ssh成功之后会马上退出退出的原因是send命令之后没有expect命令将不会被执行。 #!/usr/bin/expect -fset host_name [lindex $argv 0] set ip_addr [lindex $argv 1] set pwd [lindex $argv 2]spawn ssh $host_name$ip_addr expect {*yes/no* { send yes\r; exp_continue }*password: { send $pwd\r } }rootcurtis-Aspire-E5-471G:/home/curtis/write_code# ./func.exp rlk 192.168.0.101 123 spawn ssh rlk192.168.0.101 rlk192.168.0.101s password: rootcurtis-Aspire-E5-471G:/home/curtis/write_code#如果期望ssh后进行命令行交互可以在末尾添加interact 这里我希望ssh上去之后判断某个文件夹是否存在如果存在先删除然后在创建如果不存在则直接创建。 如何判断文件夹是否存在 rootcurtis-Aspire-E5-471G:/home/curtis/write_code# file shell shell: directory rootcurtis-Aspire-E5-471G:/home/curtis/write_code# file kkkk kkkk: cannot open kkkk (No such file or directory)注意事项如果仅仅有send命令远端将不执行send对应的命令立即退出shell交互界面 如以下例子仅存在send没有expect #!/usr/bin/expect -fset host_name [lindex $argv 0] set ip_addr [lindex $argv 1] set pwd [lindex $argv 2] set check_dir [lindex $argv 3] set send_dir [lindex $argv 4]spawn ssh $host_name$ip_addr expect {*yes/no* { send yes\r; exp_continue }*password: { send $pwd\r } } set timeout 3 expect *rlkrlk*send file $check_dir\r结果如下所示 rootcurtis-Aspire-E5-471G:/home/curtis/write_code# ./func.exp rlk 192.168.0.101 123 /home/rlk/curtis /home/curtis/write_code/Tutorials-master.zip spawn ssh rlk192.168.0.101 rlk192.168.0.101s password: Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-26-generic x86_64)* Documentation: https://help.ubuntu.com* Management: https://landscape.canonical.com* Support: https://ubuntu.com/advantage* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8sjust raised the bar for easy, resilient and secure K8s cluster deployment.https://ubuntu.com/engage/secure-kubernetes-at-the-edge616 updates can be installed immediately. 332 of these updates are security updates. To see these additional updates run: apt list --upgradableThe list of available updates is more than a week old. To check for new updates run: sudo apt update Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settingsYour Hardware Enablement Stack (HWE) is supported until April 2025. Last login: Fri Mar 17 23:00:46 2023 from 192.168.0.105 # ssh成功之后立即退出 rlkrlk:~$ rootcurtis-Aspire-E5-471G:/home/curtis/write_code#最终实现 #!/usr/bin/expect -fset host_name [lindex $argv 0] set ip_addr [lindex $argv 1] set pwd [lindex $argv 2] set check_dir [lindex $argv 3] set send_dir [lindex $argv 4]spawn ssh $host_name$ip_addr expect {*yes/no* { send yes\r; exp_continue }*password: { send $pwd\r } } set timeout 3 expect *rlkrlk*send file $check_dir\r expect {*: directory* { send rm -rf $check_dir mkdir -p $check_dir\r }*(No such file or directory)* { send mkdir -p $check_dir\r } } # 需要根据删除文件夹大小来调整超时时间 # 所谓超时时间就是等待expect期望结果的时间如果时间到了还没有达到预期就只能退出 set timeout 10 expect *rlkrlk* send exit\r expect eofspawn scp $send_dir $host_name$ip_addr:$check_dir expect {*yes/no* { send yes\r; exp_continue }*password: { send $pwd\r } } # 需要根据文件大小合理设置超时时间 set timeout 10 expect eofspawn ssh $host_name$ip_addr expect {*yes/no* { send yes\r; exp_continue }*password: { send $pwd\r } } set timeout 3 expect *rlkrlk*send unzip $check_dir/Tutorials-master.zip -d $check_dir/\r set timeout 10 expect *rlkrlk* send exit\r
http://www.hkea.cn/news/14587620/

相关文章:

  • 淄博 做网站网站模板在线制作
  • 中国建设银行招聘信息网站6线上营销推广方式都有哪些
  • 微信公众号网站制作策划书范文案例
  • 取消教育网站前置审批建筑网站登陆页面
  • 在线网站建设哪家便宜百度网站域名注册
  • 一起做英语网站vps服务器购买
  • 怎么做祝福的网站新媒体seo指的是什么
  • 门户网站建设的企业重庆网站建设子沃科技
  • 超酷网站网站建设进度安排
  • 襄阳市作风建设年 网站郑州七彩网站建设公司 评论
  • 网站建设与管理以后工作方向163企业邮箱怎么开通注册
  • 周浦高端网站建设公司西宁市规划和建设局网站
  • 做抽奖的网站犯法吗做网站最低服务器配置
  • 网站多久会被百度收录东莞网络公司排行榜
  • 住房城乡建设厅网站wordpress转发微信
  • 网站301检测网站搭建培训
  • 鞍山网站制作报价成都市住建局平台官网
  • 太原网站建设设计打开网站弹出一张图片 怎么做
  • 国外的室内设计网站查网站空间商
  • 网站建设代码流程做网站费用 会计分录
  • 网上做兼职网站有哪些hestia wordpress
  • 有网站源程序怎么做网站后台wordpress评论插件6
  • 无网站做cpa推广网站开发学徒工作如何
  • 做网站建设的注意事项国际贸易平台有哪些
  • 建设直播平台网站软件中国平安财产保险公司官网
  • 网站常用 英文网站建设纳千网络
  • 哈尔滨企业自助建站吴志国网站建设工作室
  • 电子商务网站数据库怎么做站长工具精品
  • 如何做提升自己的网站你知道吗 网站
  • 怎样建设自己的网站的视频电子商务的推广