自动互信脚本shell/expect

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动互信脚本shell/expect相关的知识,希望对你有一定的参考价值。

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 "}
"#" {send "hostname "}
}

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 "}
"#" {send "hostname "}
}

##################################################################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 "}
"#" {send "hostname "}
}

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 "}
"#" {send "hostname "}
}

以上是关于自动互信脚本shell/expect的主要内容,如果未能解决你的问题,请参考以下文章

shell expect的简单实用

shell expect的简单用法

shell expect spawnlinux expect 用法小记 看着舒服点

通过ssh主机互信打通内外网,使用shell脚本自动部署测试环境

linux自动化建互信

shell expect的简单用法