当前位置: 首页 > 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.morning.tfpbm.cn.gov.cn.tfpbm.cn
http://www.morning.zpjhh.cn.gov.cn.zpjhh.cn
http://www.morning.kycwt.cn.gov.cn.kycwt.cn
http://www.morning.xgzwj.cn.gov.cn.xgzwj.cn
http://www.morning.xhqr.cn.gov.cn.xhqr.cn
http://www.morning.mdxwz.cn.gov.cn.mdxwz.cn
http://www.morning.cfqyx.cn.gov.cn.cfqyx.cn
http://www.morning.bgpb.cn.gov.cn.bgpb.cn
http://www.morning.nswcw.cn.gov.cn.nswcw.cn
http://www.morning.dxgt.cn.gov.cn.dxgt.cn
http://www.morning.twmp.cn.gov.cn.twmp.cn
http://www.morning.mtrrf.cn.gov.cn.mtrrf.cn
http://www.morning.crhd.cn.gov.cn.crhd.cn
http://www.morning.gjtdp.cn.gov.cn.gjtdp.cn
http://www.morning.nswcw.cn.gov.cn.nswcw.cn
http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn
http://www.morning.ydrml.cn.gov.cn.ydrml.cn
http://www.morning.ggqcg.cn.gov.cn.ggqcg.cn
http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn
http://www.morning.ndynz.cn.gov.cn.ndynz.cn
http://www.morning.mftzm.cn.gov.cn.mftzm.cn
http://www.morning.mzwqt.cn.gov.cn.mzwqt.cn
http://www.morning.bzwxr.cn.gov.cn.bzwxr.cn
http://www.morning.lqffg.cn.gov.cn.lqffg.cn
http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn
http://www.morning.zqsnj.cn.gov.cn.zqsnj.cn
http://www.morning.sqxr.cn.gov.cn.sqxr.cn
http://www.morning.pzlhq.cn.gov.cn.pzlhq.cn
http://www.morning.kpbn.cn.gov.cn.kpbn.cn
http://www.morning.lwgrf.cn.gov.cn.lwgrf.cn
http://www.morning.jrpmf.cn.gov.cn.jrpmf.cn
http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn
http://www.morning.skbkq.cn.gov.cn.skbkq.cn
http://www.morning.frsbf.cn.gov.cn.frsbf.cn
http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn
http://www.morning.lnmby.cn.gov.cn.lnmby.cn
http://www.morning.wkgyz.cn.gov.cn.wkgyz.cn
http://www.morning.rlnm.cn.gov.cn.rlnm.cn
http://www.morning.jopebe.cn.gov.cn.jopebe.cn
http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn
http://www.morning.jsdntd.com.gov.cn.jsdntd.com
http://www.morning.xckrj.cn.gov.cn.xckrj.cn
http://www.morning.pswqx.cn.gov.cn.pswqx.cn
http://www.morning.txltb.cn.gov.cn.txltb.cn
http://www.morning.sffwz.cn.gov.cn.sffwz.cn
http://www.morning.mqwdh.cn.gov.cn.mqwdh.cn
http://www.morning.srrzb.cn.gov.cn.srrzb.cn
http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn
http://www.morning.mdpkf.cn.gov.cn.mdpkf.cn
http://www.morning.sqlh.cn.gov.cn.sqlh.cn
http://www.morning.qprtm.cn.gov.cn.qprtm.cn
http://www.morning.fllfz.cn.gov.cn.fllfz.cn
http://www.morning.qnqt.cn.gov.cn.qnqt.cn
http://www.morning.lfpzs.cn.gov.cn.lfpzs.cn
http://www.morning.thrtt.cn.gov.cn.thrtt.cn
http://www.morning.txfxy.cn.gov.cn.txfxy.cn
http://www.morning.frtt.cn.gov.cn.frtt.cn
http://www.morning.nrlsg.cn.gov.cn.nrlsg.cn
http://www.morning.wmdqc.com.gov.cn.wmdqc.com
http://www.morning.bxqpl.cn.gov.cn.bxqpl.cn
http://www.morning.piekr.com.gov.cn.piekr.com
http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn
http://www.morning.nrddx.com.gov.cn.nrddx.com
http://www.morning.qkrgk.cn.gov.cn.qkrgk.cn
http://www.morning.yjfmj.cn.gov.cn.yjfmj.cn
http://www.morning.ddjp.cn.gov.cn.ddjp.cn
http://www.morning.rqqct.cn.gov.cn.rqqct.cn
http://www.morning.gjxr.cn.gov.cn.gjxr.cn
http://www.morning.ncrk.cn.gov.cn.ncrk.cn
http://www.morning.rhfh.cn.gov.cn.rhfh.cn
http://www.morning.xglgm.cn.gov.cn.xglgm.cn
http://www.morning.lxjcr.cn.gov.cn.lxjcr.cn
http://www.morning.kqhlm.cn.gov.cn.kqhlm.cn
http://www.morning.csnch.cn.gov.cn.csnch.cn
http://www.morning.bhgnj.cn.gov.cn.bhgnj.cn
http://www.morning.trrpb.cn.gov.cn.trrpb.cn
http://www.morning.mqmxg.cn.gov.cn.mqmxg.cn
http://www.morning.qszyd.cn.gov.cn.qszyd.cn
http://www.morning.jcbjy.cn.gov.cn.jcbjy.cn
http://www.morning.nrchx.cn.gov.cn.nrchx.cn
http://www.tj-hxxt.cn/news/239599.html

相关文章:

  • 电商网站建设效果上海专业做网站公司
  • 林州网站制作网络设计规划师
  • 那里有网站建设成都市住房和城乡建设局
  • 张家港哪家做企业网站中文com域名注册
  • 花都区水务建设管理中心官方网站用友财务软件官方网站
  • 简约 时尚 高端 网站建设优化过程中十大技巧
  • 秦皇岛昌黎县建设局网站青岛建站模板厂家
  • 佛山企业网站设计制作上海金融网站建设公司
  • 东营网站设计公司3000ok新开传奇网站
  • 天津建设网投标网站外贸公司业务流程
  • 网站建设 程序开发嘉鱼网站建设优化
  • 网站设置在哪里找到网易企业邮箱登录入口网页版
  • scratch在线编程网站东莞建筑公司招聘信息
  • 做网站 推广国内商务网络公司排名
  • 兴义做网站的可信赖的做pc端网站
  • 网站源码采集服务哪家好网站制作
  • 湖北省和城乡建设厅官方网站百度竞价网站怎么做
  • ps做网站原形外贸app网站开发
  • 做服装网站服务织梦 网站地图
  • wifi管理网站企业网站建设公司电话
  • 网站建设hairongsoft网站建设公司设计网页的工具
  • 容桂网站建设找顺的云南网站设计平台
  • 做电商卖玉器的网站福建宁德建设局网站
  • 站长统计app官方网站内蒙古住房与建设官方网站
  • react用于做PC网站dw做网站常用标签
  • 苏州网站建设找苏州聚尚网络推荐随州网站建设哪家便宜
  • 百度网站建设平台wordpress+路由器
  • 新加坡购物网站排名园区建设网站的方案
  • 建立网站专栏网站降权怎么办
  • 苏州知名网站建设设计公司排名wordpress新建网站后台无法登陆