天天看点

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

分发系统:shell 上线脚本expect实现远程传输文件,执行命令,系统上线等功能

expect 脚本远程登录

vim 1.expect

#! /usr/bin/expect

set host "192.168.91.129"

set passwd "1q2w3e"

spawn ssh root@$host

expect {

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

"assword:" { send "$passwd\r" }

}

interact *停留在远程机器上,如果想登录到远程机器上退出来,使用expect或者eof,如果都不加,立马就退出来

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

登录到aminglinux02上

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

expect脚本远程执行命令

vim 2.expect

#!/usr/bin/expect

set user "root"

spawn ssh [email protected]

"password:" { send "$passwd\r" }

expect "]"

send "touch /tmp/12.txt\r"

send "echo 1212 > /tmp/12.txt\r"

expect "]*"

send "exit\r"

[root@aminglinux-001 ~]# chmod a+x 2.expect

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

继续阅读