-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
##yum install expect -y | ||
for i in `awk '{print $1}' passwd.txt` | ||
do | ||
j=`awk -v I="$i" '{if(I==$1)print $2}' passwd.txt` | ||
k=`awk -v I="$i" '{if(I==$1)print $3}' passwd.txt` | ||
|
||
expect login.exp $i $j $k | ||
#~/.ssh/known_hosts存在重复KEY处理 | ||
#echo $i | ||
#check1=`cat ~/.ssh/known_hosts|grep "$i ssh"` | ||
#echo $check1 | ||
#if [ "$check1" == "" ];then | ||
#expect login.exp $i $j $k | ||
#else | ||
#sed -i "/$i ssh/d" ~/.ssh/known_hosts | ||
#expect login.exp $i $j $k | ||
#fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/expect | ||
set timeout 10 | ||
set ipaddress [lindex $argv 0] | ||
set username [lindex $argv 1] | ||
set passwd [lindex $argv 2] | ||
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$ipaddress | ||
expect { | ||
#first connect, no public key in ~/.ssh/known_hosts | ||
"Are you sure you want to continue connecting (yes/no)?" { | ||
send "yes\r" | ||
expect "password:" | ||
send "$passwd\r" | ||
} | ||
#already has public key in ~/.ssh/known_hosts | ||
"password:" { | ||
send "$passwd\r" | ||
} | ||
"Now try logging into the machine" { | ||
#it has authorized, do nothing! | ||
} | ||
} | ||
expect eof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/expect -f | ||
set ipaddress [lindex $argv 0] | ||
set username [lindex $argv 1] | ||
set passwd [lindex $argv 2] | ||
if { $argc != 3 } { | ||
puts stderr $passwd | ||
puts stderr $username | ||
exit 1 | ||
} | ||
set timeout 30 | ||
spawn ssh $username@$ipaddress | ||
expect { | ||
"yes/no" { send "yes\r";exp_continue } | ||
"password:" { send "$passwd\r" } | ||
} | ||
expect "]*" | ||
send "date \r" | ||
send "df -h\r" | ||
send "exit\r " | ||
send "exit\r " | ||
expect eof {exit 1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
192.168.10.11 root qqqwww123 | ||
192.168.10.12 root qqqwww123 |