-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_ssh.sh
executable file
·40 lines (29 loc) · 978 Bytes
/
clean_ssh.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/expect -f
# See http://stackoverflow.com/questions/19403360/how-to-use-expect-to-copy-a-public-key-to-a-host
set timeout 9
set username [lindex $argv 0]
set hostname [lindex $argv 1]
set password [lindex $argv 2]
spawn scp -q ./cleaner.sh $username@$hostname:
expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
"*re you sure you want to continue connecting" {
send "yes\r"
exp_continue
}
"*ssword" {
send "$password\r"
exp_continue
}
}
spawn ssh -q -o StrictHostKeyChecking=no $username@$hostname /bin/bash ./cleaner.sh
expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
eof { send_user "\nSSH failure for $hostname\n"; exit 1 }
"*re you sure you want to continue connecting" {
send "yes\r"
exp_continue
}
"*ssword" { send "$password\r"; exp_continue }
}
#eof { send_user "\nSSH failure for $hostname\n"; exit 1 }