天天看點

分發系統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遠端登入,執行指令,傳遞參數

繼續閱讀