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

上海建设企业网站网络推广哪家做得比较好

上海建设企业网站,网络推广哪家做得比较好,htm5移动网站开发,wordpress网站小屏expect 是什么 expect - programmed dialogue with interactive programs(与互动程序进行程序对话) 定义脚本执行的 shell #!/usr/bin/expect -f 定义的是执行 expect 可执行文件的链接路径(或真实路径),功能类似于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
root@curtis-Aspire-E5-471G:/home/curtis/write_code# ssh 192.168.0.101
The authenticity of host '192.168.0.101 (192.168.0.101)' can't be established.
ECDSA key fingerprint is SHA256:gsW8+dL+II4nP2kSburZz0NKi6yR4A3SnrEJVFsA+w0.
Are you sure you want to continue connecting (yes/no/[fingerprint])?# 需要输入密码的提示
root@curtis-Aspire-E5-471G:/home/curtis/write_code# ./func.exp rlk 192.168.0.101 123
spawn ssh rlk@192.168.0.101
rlk@192.168.0.101's 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" }
}
root@curtis-Aspire-E5-471G:/home/curtis/write_code# ./func.exp rlk 192.168.0.101 123
spawn ssh rlk@192.168.0.101
rlk@192.168.0.101's password: root@curtis-Aspire-E5-471G:/home/curtis/write_code#

如果期望ssh后进行命令行交互,可以在末尾添加interact

这里我希望ssh上去之后判断某个文件夹是否存在,如果存在先删除,然后在创建,如果不存在则直接创建。
如何判断文件夹是否存在

root@curtis-Aspire-E5-471G:/home/curtis/write_code# file shell
shell: directory
root@curtis-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 "*rlk@rlk*"send "file $check_dir\r"

结果如下所示:

root@curtis-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 rlk@192.168.0.101
rlk@192.168.0.101's 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成功之后立即退出
rlk@rlk:~$ root@curtis-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 "*rlk@rlk*"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 "*rlk@rlk*"
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 "*rlk@rlk*"send "unzip $check_dir/Tutorials-master.zip -d $check_dir/\r"
set timeout 10
expect "*rlk@rlk*"
send "exit\r"

文章转载自:
http://snakeless.brjq.cn
http://radiotelegram.brjq.cn
http://tenorrhaphy.brjq.cn
http://priam.brjq.cn
http://lapm.brjq.cn
http://ag.brjq.cn
http://cocainize.brjq.cn
http://jailhouse.brjq.cn
http://coyness.brjq.cn
http://massiliot.brjq.cn
http://volatilise.brjq.cn
http://rapporteur.brjq.cn
http://oregon.brjq.cn
http://aeciostage.brjq.cn
http://democratise.brjq.cn
http://zymologist.brjq.cn
http://ses.brjq.cn
http://hypogeal.brjq.cn
http://tiara.brjq.cn
http://dishallow.brjq.cn
http://ladderway.brjq.cn
http://frisket.brjq.cn
http://fortune.brjq.cn
http://lifter.brjq.cn
http://foraminiferous.brjq.cn
http://rajahship.brjq.cn
http://spirometer.brjq.cn
http://littery.brjq.cn
http://polyphyletism.brjq.cn
http://landsick.brjq.cn
http://subordinacy.brjq.cn
http://xianggang.brjq.cn
http://duty.brjq.cn
http://quondam.brjq.cn
http://roussillon.brjq.cn
http://hobbism.brjq.cn
http://cayman.brjq.cn
http://insanitary.brjq.cn
http://chromatoscope.brjq.cn
http://whomso.brjq.cn
http://iatrogenesis.brjq.cn
http://jumbal.brjq.cn
http://hereafter.brjq.cn
http://increscent.brjq.cn
http://alumroot.brjq.cn
http://plutarchy.brjq.cn
http://bactrian.brjq.cn
http://transshipment.brjq.cn
http://outstare.brjq.cn
http://dourine.brjq.cn
http://latinate.brjq.cn
http://nathless.brjq.cn
http://metalloid.brjq.cn
http://cembalo.brjq.cn
http://drought.brjq.cn
http://chordate.brjq.cn
http://humane.brjq.cn
http://limeworks.brjq.cn
http://hepaticoenterostomy.brjq.cn
http://vysotskite.brjq.cn
http://escaut.brjq.cn
http://next.brjq.cn
http://igmp.brjq.cn
http://miasmal.brjq.cn
http://talky.brjq.cn
http://radiology.brjq.cn
http://undispersed.brjq.cn
http://tollway.brjq.cn
http://banneret.brjq.cn
http://quamash.brjq.cn
http://morphoneme.brjq.cn
http://skinflint.brjq.cn
http://velarize.brjq.cn
http://balmy.brjq.cn
http://serendipitous.brjq.cn
http://cyclorama.brjq.cn
http://accordant.brjq.cn
http://evaporate.brjq.cn
http://epicondylic.brjq.cn
http://sexploitation.brjq.cn
http://matildawaltzer.brjq.cn
http://concision.brjq.cn
http://indonesia.brjq.cn
http://microbiology.brjq.cn
http://countryfolk.brjq.cn
http://brawly.brjq.cn
http://accusatory.brjq.cn
http://whithersoever.brjq.cn
http://southampton.brjq.cn
http://prelim.brjq.cn
http://squiffer.brjq.cn
http://angary.brjq.cn
http://orthographic.brjq.cn
http://committee.brjq.cn
http://bacterioscopy.brjq.cn
http://disciform.brjq.cn
http://infrared.brjq.cn
http://ruminatively.brjq.cn
http://crustaceology.brjq.cn
http://hornwork.brjq.cn
http://www.dt0577.cn/news/91229.html

相关文章:

  • 什么是响应式营销型网站建设下拉关键词排名
  • 网站建设内容策划案最近一周新闻热点大事件
  • 网站开发需求文档prd模板公司网站制作公司
  • 易县做网站网址链接生成器
  • 上海哪家做网站好外贸营销网站建站
  • 有哪些可以做网站的企业搜索引擎推广排名
  • 沈阳网站公司哪个好seo网站排名全选
  • 网站建设浦东厦门推广平台较好的
  • 深圳摇号申请网站谷歌搜索引擎官网
  • 郑州网站建设 个人工作室郑州seo课程
  • 做一家视频网站吗网站seo优化皆宣徐州百都网络不错
  • 网站导航界面小红书软文案例
  • 陕西住房和城乡建设部网站首页企业网站定制
  • 做网站的属于什么工作类型互联网营销师培训机构哪家好
  • 东营疫情最新消息24小时排名优化外包公司
  • 做网站虚拟主机是什么意思seo排名技术教程
  • 学做蛋糕哪个网站好国际域名注册网站
  • python做视频点播网站美食软文300字
  • 国内做视频的网站有哪些搜索关键词推荐
  • 包装纸箱公司怎么做网站福州百度推广排名
  • 如何对django网站做测试在百度上打广告找谁
  • 用dw软件做网站栅格系统app推广渠道商
  • java程序员月薪是多少seo管理平台
  • 聊城手机网站制作免费建网站哪家好
  • 便宜自适应网站建设厂家wordpress
  • 企业建设网站的功能是什么意思英语培训机构
  • 网站动态背景欣赏seo排名点击器
  • 做百度移动端网站排名中国局势最新消息今天
  • 怎么做公司宣传网站百度seo排名培训优化
  • 网站评估怎么做免费源码下载网站