自动互信脚本shell/expect

匿名 (未验证) 提交于 2019-12-03 00:41:02
cat >forallHost.sh
#!/bin/bash
for i in {1..9}
do
/usr/bin/expect autoyes.sh $i
done

cat >autoyesMkdir.sh
#!/usr/bin/expect
set time 1
set i [ lindex $argv 0 ]
spawn ssh 192.168.4.$i "mkdir /root/.ssh"
expect {
"password:" {send "123456\n"}
"#" {send "hostname\n"}
}

cat >autoyesUprsa.sh
#!/usr/bin/expect
set time 1
set i [ lindex $argv 0 ]
spawn scp -r /root/.ssh 192.168.4.$i:/root/.ssh
expect {
"password:" {send "123456\n"}
"#" {send "hostname\n"}
}

##################################################################3
cat uprsa.sh
#!/bin/bash -r /root/.ssh/ 192.168.4.$i:/root/.ssh/.
for i in {1..9}
do
scp -r /root/.ssh/
192.168.4.$i:/root/.ssh/.
done

cat startvm.sh
#!/bin/bashsh start rh7_node$i
for i in {1..9}
do
virsh start rh7_node$i
done

cat note
local ip --> 76.121.210.172
172.25.254.250
server -->172.25.0.11

cat forallHost.sh
#!/bin/bash
for i in {1..9}
do
expect autoues.sh $i
done

cat autoyes.sh
#!/usr/bin/expect
set time 1
set i [ lindex $argv 0 ]
spawn ssh 192.168.4.$i "mkdir /root/.ssh"
expect {
"password:" {send "123456\n"}
"#" {send "hostname\n"}
}

cat autoyesUprsa.sh
#!/usr/bin/expect
set time 1
set i [ lindex $argv 0 ]
spawn scp -r /root/.ssh 192.168.4.$i:/root/.ssh
expect {
"password:" {send "123456\n"}
"#" {send "hostname\n"}
}

原文:http://blog.51cto.com/creatoryuan/2144514

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!