加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

strive_tan shell编程实战2-分发系统

发布时间:2020-12-16 01:42:52 所属栏目:安全 来源:网络整理
导读:1.??expect的应用 ?1)传输文件 ?2)远程执行命令,无需交互,无需输入密码 ?3)上线的shell脚本(工具),核心是expect,即分发系统 2. expect的安装 ? ?yum install? -y expect 3.??expect语言实例1:自动远程登陆某台服务器 #! /usr/bin/expect set host

1.??expect的应用

?1)传输文件

?2)远程执行命令,无需交互,无需输入密码

?3)上线的shell脚本(工具),核心是expect,即分发系统

2. expect的安装

? ?yum install? -y expect

3.??expect语言实例1:自动远程登陆某台服务器

#! /usr/bin/expect

set host "192.168.133.132"

set passwd "123456"

spawn ssh [email?protected]$host

expect {

"yes/no" { send "yesr"; exp_continue}

"password:" { send "$passwdr" }

}

interact

4.?expect语言实例2:自动远程登陆某台服务器后,并执行命令

#!/usr/bin/expect

set user "root"

set passwd "123456"

spawn ssh [email?protected]

expect {

"yes/no" { send "yesr"; exp_continue}

"password:" { send "$passwdr" }

}

expect "]*"

send "touch /tmp/12.txtr"

expect "]*"

send "echo 1212 > /tmp/12.txtr"

expect "]*"

send "exitr"

5. expect脚本之传递参数

#!/usr/bin/expect

set user [lindex $argv 0]

set host [lindex $argv 1]

set passwd "123456"

set cm [lindex $argv 2]

spawn ssh [email?protected]$host

expect {

"yes/no" { send "yesr"}

"password:" { send "$passwdr" }

}

expect "]*"

send "$cmr"

expect "]*"

send "exitr"

? ? ???$argv0?? 表示要传递给变量user的参数;$argv1,$argv2同理

6.?expect脚本之同步文件

? ?

7.??expect脚本之构建文件分发系统

? ?

8.?

#!/usr/bin/expect

set host [lindex $argv 0]

set passwd "123456"

set cm [lindex $argv 1]

spawn ssh [email?protected]$host

expect {

"yes/no" { send "yesr"}

"password:" { send "$passwdr" }

}

expect "]*"

send "$cmr"

expect "]*"

send "exitr"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读