分发系统expect远程登录,执行命令,传递参数

分发系统:shell 上线脚本expect实现远程传输文件,执行命令,系统上线等功能
expect 脚本远程登录
vim 1.expect
#! /usr/bin/expect
set host "192.168.91.129"
set passwd "1q2w3e"
spawn ssh [email protected]$host
expect {
"yes/no" { send "yes\r"; exp_continue}
"assword:" { send "$passwd\r" }
}
interact *停留在远程机器上,如果想登录到远程机器上退出来,使用expect或者eof,如果都不加,立马就退出来

登录到aminglinux02上

expect脚本远程执行命令
vim 2.expect
#!/usr/bin/expect
set user "root"
set passwd "1q2w3e"
spawn ssh [email protected]

expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
expect "]"
send "touch /tmp/12.txt\r"
expect "]
"
send "echo 1212 > /tmp/12.txt\r"
expect "]*"
send "exit\r"
[[email protected] ~]# chmod a+x 2.expect

expect传递参数
#!/usr/bin/expect

set user [lindex $argv 0]
set host [lindex $argv 1]
set passwd "1q2w3e"
set cm [lindex $argv 2]
spawn ssh [email protected]$host

expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect "]"
send "$cm\r"
expect "]
"
send "exit\r"
[[email protected] ~]# chmod a+x 3.expect
只传递一个参数

传递多个参数

原文地址:http://blog.51cto.com/13528516/2107908

时间: 2024-08-27 23:12:10

分发系统expect远程登录,执行命令,传递参数的相关文章

自动远程登录执行命令

1.自动登录问题,在不考虑秘钥文件情况下想登录远程设备,必须提供ip地址,用户名和密码三个信息,通过telnet或ssh进行登录,可在telnet或ssh的命令中并未找到可指定password的地方. C:\>telnet -h telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]] -a      企图自动登录.除了用当前已登陆的用户名以外,与 -l 选项相同. -e      跳过字符来进入 telnet

expect 自动登录执行命令后退出

yum install -y rsync yum install -y expect chmod a+x 2.expect ./2.expect

分发系统-expect讲解,expect脚本远程登录,expect脚本远程执行命令,expect脚本

分发系统-expect讲解 业务越来越大,网站app,后端,编程语言是php,所以就需要配置lamp或者lnmp,最好还需要吧代码上传到服务器上:但是因为业务增加,代码增加,多台机器,就会非常麻烦:这是只需要一个分发系统,就可以把每次更新的代码发布到需要更新的服务器上 expect,是一种脚本语言:通过他可以实现传代码上线,也可以登录机器输入命令 首先要准备一台模板机器,机器的IP,对应用户的密码,通过rsync同步代码,还可以通过expect去执行某些命令 expect脚本远程登录 yum i

分发系统-expect

分发系统-expect expect是一种自动交互语言,能实现在shell脚本中为scp和ssh等自动输入密码自动登录.登录多台系统执行指定命令:创建文件最好以expect结尾: 安装包 yum install -y expect 自动远程登录 1.expect代码: #! /usr/bin/expect set host "192.168.188.3" set passwd "123456" spawn ssh [email protected]$host exp

shell项目-分发系统-expect

安装expect [[email protected] ~]# yum install -y expect 用脚本登陆远程机器编写脚本1.expect内容如下: [[email protected] expect]# vim 1.expect #!/usr/bin/expect set host "192.168.130.128" #定义变量 set passwd "6811327" #定义变量 spawn ssh [email protected]$host ex

使用定时器settimeout、setInterval执行能传递参数的函数

无论是window.setTimeout还是window.setInterval,在使用函数名作为调用句柄时都不能带参数,而在许多场合必须要带参数,这就需要想方法解决.经网上查询后整理如下: 例如对于函数hello(_name),它用于针对用户名显示欢 迎信息: var userName="jack"; //根据用户名显示欢迎信息 function hello(_name){ alert("hello,"+_name); } 这时,如果企图使用以下语句来使hello

expect脚本同步文件expect脚本指定host和要同步的文件 构建文件分发系统批量远程执行命令

20.31 expect脚本同步文件#!/usr/bin/expectset passwd "liang.123"spawn rsync -av [email protected]:/tmp/12.txt /tmp/ 将远程的/tmp/12.txt同步到本地的机器上 expect {"yes/no" { send "yes\r"} 第一次会提示yes或no"password:" { send "$passwd\r&q

expect脚本同步文件 expect脚本指定host和要同步的文件 构建文件分发系统 批量远程执行命令

自动同步文件 #!/usr/bin/expect set passwd "123456" spawn rsync -av [email protected]192.168.133.132:/tmp/12.txt /tmp/ expect { "yes/no" { send "yes\r"} "password:" { send "$passwd\r" } } expect eof 指定host和要同步的文件

expect脚本同步文件,expect脚本指定host和要同步的文件,构建文件分发系统,批量远程执行

expect脚本同步文件 在一台机器上把文件同步到多台机器上 自动同步文件 [[email protected] sbin]# vim 4.expect #!/usr/bin/expect set passwd "s5381561" spawn rsync -av [email protected]:/tmp/12.txt /tmp/ expect { "yes/no" { send "yes\r"} "password:"