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

涪陵网站建设谷歌google官网入口

涪陵网站建设,谷歌google官网入口,做网站公司郑州汉狮,杭州做网站的好公司有哪些目录 绪论 1、here Document免交互 1.1 格式 1.2 cat结合免交互实现重定向输出到指定文件 1.3 变量替换 2、Expect免交互 2.1 三种写法 3、免交互实现普通用户切换root 3.1 send_user 4、接收参数 5、嵌入执行模式 6、ssh远程登录 绪论 免交互:不需要人…

目录

绪论

1、here   Document免交互

1.1 格式

1.2 cat结合免交互实现重定向输出到指定文件

 1.3 变量替换

2、Expect免交互

2.1 三种写法

3、免交互实现普通用户切换root

3.1 send_user

4、接收参数

5、嵌入执行模式

6、ssh远程登录


绪论

免交互:不需要人为控制就可以完成的自动化操作(自动化运维)

1、here   Document免交互

使用i/o(输入/输出)重定向的方式,将命令的列表提供给交互式的程序或者命令

cat read 是一种标准输入,只能接受正确的指令或者命令

1.1 格式

命令  <<标记

...

...

标记

eg:

注意事项

· 标记可以使用人以合法字符(通常用EOF)

· 结尾的标记一定要顶格写,前面不能有任何字符

· 结尾的标记后面,也不能有任何字符,包括空格

· 如果开头的标记前有空格,这个空格会被自动省略 

eg:read  i  <<EOF      read只能输入一次

>123

>EOF

echo  $i

1.2 cat结合免交互实现重定向输出到指定文件

 1.3 变量替换

vim  test.sh进入编辑

#!/bin/bash

file="test.txt"

i="school"

cat  >  $file  <<EOF

I  am  going  to  $i

EOF  保存退出

2、Expect免交互

tcl语言基础之上的一种工具,自动化测试和控制,在脚本中解决交互的问题

转义符:\n 换行 \t制表符,tab键 \r回车 \b退格键,就是删除键

基本命令格式: #!/usr/bin/expect

语法:

· spawn后面通常跟一个linux的执行命令,表示开启一个会话,启动一个进程,并且跟踪后续的交互信息

· expect,捕获,上一次执行的命令中,是否包含指定的字符串,如果有立即返回,否则等待超时,自动退出(默认超时时间为10s)

· expect 只能捕获由spawn启动的进程输出

· send 向进程发送字符串,用于模拟用户的输入,该命令不能自动回车,一般后面加一个回车键:\r 或者\n

2.1 三种写法

第一种写法
#!/use/bin/expect
set  timeout  5
spawn  passwd  lisi
expect  "新的密码"
send  "abc123\r"
expect  "重新输入新的密码"
send  "abc123\r"
expect  eof第二种写法
#!/use/bin/expect
set  timeout  5
spawn  passwd  lisi
expect  "New  password"  {send  "123\r"}
expect  "Retype  new  password"  {send  "123\r"}
expect  eof第三种写法:多分支结构
#!/use/bin/expect
set  timeout  5
spawn  passwd  lisi
expect{
"密码1"{send  "abc123\r"}
"密码2"{send  "abc123\r"}
"密码3"{send  "abc123\r"}      只要匹配其中一个情况,执行相应的send语句,然后退出}
结束符
expect  eof   会切换回之前的终端
interact 留在当前终端不变
set 设置超市等待时间,默认是10s
set timeout 5  -1()则表示永不超时

3、免交互实现普通用户切换root

vim  qiehuan.sh
#!/usr/bin/expect
set  timeout  5
spawn  su  root
expect  "passwd"
send  "123\r"
expect  eof  保存退出
chmod 777 目录
su  -  lisi
sh  qiehuan.sh

expect_continue 可以在expect判断之后,继续匹配expect,捕获的其他内容,类似于脚本中continue,表示允许继续向下执行指令

使用expect_continue的结束语不能使用expect  eof

expect  {

"(yes/no)"  {send  "yes\r";exp_continue}

"passwd"  {send"123\r"}

}

3.1 send_user

send_user 会先信息,相当于echo跟上用户想要输出的内容

4、接收参数

类似于shell当中的位置变量$1 $2

set  hostname  [linux  $argv  0]  $1

 set  password  [linux  $argv  0]  $2

eg:
set  timeout  5
set  usr  [lindex  $argv  0]
set  passwd  [lindex  $argv  1]
spawn  su  -  $user
expect  "密码" (或者passwd)
send  "$passwd\r"
expect  "]$"
send_user  "普通用户"
expect  "]#"
send_user  "管理员"
interact  
保存退出
./qiehuan  lisi  123

5、嵌入执行模式

如果涉及终端切换,最好不要用嵌入模式

将expect过程融入shell中,方便执行和处理

eg:vim  useradd.sh
#!/bin/bash
user=$1
passwd=$2
useradd  $user
/usr/bin/expect  <<  -EOF
#expect 开始表示
spawn  passwd  $user
expect  "新的*"
send  "${passwd}\r"
expect  "重新*"
send  "${passwd}\r"
expect  eof
EOF
保存退出
sh  useradd.sh  lisi  123

6、ssh远程登录

#!/usr/bin/expect
set ip 192.168.233.30  #指定远程登录的ip地址
set user root
#指定为root用户
set password 123
#设定密码为123
set timeout 5spawn ssh $user@$ip   
expect  {"yes/no" isend "yes\r" ;exp_continue}
"password" isend " $password\r" }
}
expect eof保存退出
chmod   777   ssh.sh
./ssh.sh

6.1 通过传参的方式实现

#!/usr/bin/expect
set name [lindex $argv 0]
set ip [lindex $argv 1]
set password [lindex $argv 2]
set timeout 5
spawn ssh
$name@$ip
expect {
"refused" {send_ _user "访问被拒绝\r"}
"No route to host" {send_ _user "主机名或者ip地址有误\n"}
"yes/no" {send "yes\r" ;exp_ continue}
password" {send " $password\r"}
}
expect eof

保存退出

./ssh.sh  root  20.0.0.30  123


文章转载自:
http://dinncokakemono.ydfr.cn
http://dinncogigantic.ydfr.cn
http://dinncofestinate.ydfr.cn
http://dinnconephrism.ydfr.cn
http://dinncoaffettuoso.ydfr.cn
http://dinncomowe.ydfr.cn
http://dinncoplaid.ydfr.cn
http://dinncotetartohedral.ydfr.cn
http://dinncoedentulous.ydfr.cn
http://dinncovoltairean.ydfr.cn
http://dinncomillier.ydfr.cn
http://dinncosystematically.ydfr.cn
http://dinncoinvigorate.ydfr.cn
http://dinncooversew.ydfr.cn
http://dinncoessence.ydfr.cn
http://dinncobonhomous.ydfr.cn
http://dinncogradational.ydfr.cn
http://dinncotelerecording.ydfr.cn
http://dinncodivest.ydfr.cn
http://dinncoteleocracy.ydfr.cn
http://dinncoampliation.ydfr.cn
http://dinncoavoirdupois.ydfr.cn
http://dinncosacramentalist.ydfr.cn
http://dinncocolonizer.ydfr.cn
http://dinncoteratoid.ydfr.cn
http://dinncoclinician.ydfr.cn
http://dinncoarteriolar.ydfr.cn
http://dinncolimbal.ydfr.cn
http://dinncoquotha.ydfr.cn
http://dinncotruetype.ydfr.cn
http://dinncoonomasticon.ydfr.cn
http://dinncofactorable.ydfr.cn
http://dinncocorymbiferous.ydfr.cn
http://dinncosatyr.ydfr.cn
http://dinncomucilaginous.ydfr.cn
http://dinncorhinoplasty.ydfr.cn
http://dinncoflambeaux.ydfr.cn
http://dinncowhitsunday.ydfr.cn
http://dinncovina.ydfr.cn
http://dinncorecloser.ydfr.cn
http://dinncolha.ydfr.cn
http://dinncoradiotoxic.ydfr.cn
http://dinncofelafel.ydfr.cn
http://dinncoseated.ydfr.cn
http://dinncorepled.ydfr.cn
http://dinncotoothed.ydfr.cn
http://dinncowhites.ydfr.cn
http://dinncodecentralisation.ydfr.cn
http://dinncohammurapi.ydfr.cn
http://dinncostringent.ydfr.cn
http://dinncophlebitis.ydfr.cn
http://dinncospencite.ydfr.cn
http://dinncogyrocompass.ydfr.cn
http://dinncoaeonian.ydfr.cn
http://dinncohashbury.ydfr.cn
http://dinncokeresan.ydfr.cn
http://dinncocarotenoid.ydfr.cn
http://dinncocanossa.ydfr.cn
http://dinncodrake.ydfr.cn
http://dinncocrying.ydfr.cn
http://dinncounsubstantial.ydfr.cn
http://dinncoplantation.ydfr.cn
http://dinncogetter.ydfr.cn
http://dinncoheliolatry.ydfr.cn
http://dinncotrainload.ydfr.cn
http://dinncoirisated.ydfr.cn
http://dinncowhiggism.ydfr.cn
http://dinncogeonavigation.ydfr.cn
http://dinncohanuka.ydfr.cn
http://dinncosaree.ydfr.cn
http://dinncoreptilian.ydfr.cn
http://dinnconursling.ydfr.cn
http://dinncourology.ydfr.cn
http://dinncodistilment.ydfr.cn
http://dinncobrassily.ydfr.cn
http://dinncoscram.ydfr.cn
http://dinncofletcherite.ydfr.cn
http://dinncoberretta.ydfr.cn
http://dinncobebop.ydfr.cn
http://dinncodissected.ydfr.cn
http://dinncohalloo.ydfr.cn
http://dinncoalegar.ydfr.cn
http://dinncocorrelativity.ydfr.cn
http://dinncotroilism.ydfr.cn
http://dinncomachisma.ydfr.cn
http://dinncoabstersive.ydfr.cn
http://dinncogreasewood.ydfr.cn
http://dinncopreen.ydfr.cn
http://dinncoclimatotherapy.ydfr.cn
http://dinncocopular.ydfr.cn
http://dinncobouvet.ydfr.cn
http://dinncowicked.ydfr.cn
http://dinncocharpoy.ydfr.cn
http://dinncobeneficent.ydfr.cn
http://dinnconotam.ydfr.cn
http://dinncopidgin.ydfr.cn
http://dinncosubception.ydfr.cn
http://dinncocertainty.ydfr.cn
http://dinncospirolactone.ydfr.cn
http://dinncothermotensile.ydfr.cn
http://www.dinnco.com/news/127472.html

相关文章:

  • wordpress静态化链接seo还有哪些方面的优化
  • 网络网站开发设计怎么自己做网站
  • 怎么做微信电影网站seo研究中心怎么样
  • 西安买公司的网站建设济南搜索引擎优化网站
  • 门户网站建设工作流程国产最好的a级suv88814
  • wordpress如何下载百度关键词seo排名优化
  • 美女做游戏广告视频网站营销网点机构号
  • 青海保险网站建设公司电商平台营销策划方案
  • html手机网站怎么做百度小说搜索热度排行榜
  • 如何做网站推广十大经典案例
  • 微信公众平台小程序官网宁波seo整体优化公司
  • 虚拟网站建设最能打动顾客的十句话
  • 网站变宽屏怎么做网络营销方法有哪些
  • 商城网站 免费开源互联网推广好做吗
  • 票务网站开发灰色推广
  • w3school网站建设教程宁波网络优化seo
  • 企业网站模板 简洁深圳网站制作
  • 大连微信网站制作视频互联网推广选择隐迅推
  • 恩施网站开发百度应用市场下载安装
  • 狮山建网站企业管理培训课程网课免费
  • 做网站都需要什么软件百度手机快速排名点击软件
  • 网页游戏网站快手关键词优化排名详细步骤
  • 网站建设linux太原网站制作优化seo公司
  • 招聘网站开发需求百度推广代理商与总公司的区别
  • 建网站需要花哪些钱seo在线网站推广
  • c2b模式的代表企业有哪些百度快速排名优化工具
  • 电子商务网站推广怎么做seo编辑培训
  • 做ppt的网站兼职福建网站建设制作
  • 全国建造师信息查询天津seo网站排名优化公司
  • 网站改版需要注意网络营销能干什么工作