expect

#!/usr/bin/expect

set host 192.168.1.124

set user root

set password "root"

spawn ssh $user@$host

expect "yes/no" { send "yes\r" }

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

expect "\[$user\@" { send "pwd > /tmp/$user.txt ; exit\r" }

interact 


------------------------------------------------------------->腳本傳參$1 = set host [lindex $argv 0]

#!/usr/bin/expect

set host [lindex $argv 0]

set user root

set password "root"

spawn ssh $user@$host

expect "yes/no" { send "yes\r" }

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

expect "\[$user\@" { send "echo 'my name is you!' > /tmp/$user.txt ; exit\r" }

interact


------------------------------------------------------------------>

#!/bin/bash

known_file=/root/.ssh/known_hosts

rm -rf ${known_file:-/tmp/*}

expect <<EOF

set timeout 5

spawn ssh [email protected]

expect "password" {send "123456\r"}

expect "#" {send "echo 'my name is you' >/tmp/root7.txt\r"}

expect "#" {send "exit\r"}

EOF


------------------------------------------------------->給254檯安裝httpd服務

#!/bin/bash

known_file=/root/.ssh/known_hosts

rm -rf ${known_file:-/tmp/*}

for i in $(seq 254)

do

expect <<EOF

spawn ssh [email protected].$i

expect "yes/no" {send "yes\r"}

expect "password" {send "123456\r"}

expect "#" {send "echo 'yum -y install httpd\r"}

expect "#" {send "exit\r"}

EOF

done


------------------------------------------------------>給254發密鑰 ssh-copy-id

#!/bin/bash

for i in $(seq 254)

do

expect <<EOF

spawn ssh-copy-id [email protected].$i

expect "yes/no" {send "yes\r"}

expect "password" {send "123456\r"}

expect "#" {send "exit\r"}

EOF

done




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章