-
Notifications
You must be signed in to change notification settings - Fork 0
/
automat1.sh
executable file
·47 lines (44 loc) · 1.02 KB
/
automat1.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
41
42
43
44
45
46
47
#!/usr/bin/expect
#
#
set timeout 60
set prompt "(%|#|\\$|%\]) $"
set fid [open ./hosts.list r]
set contents [read -nonewline $fid]
close $fid
stty echo
send_user "\nUsername for SSH connection: "
expect_user -re "(.*)\n" {set sshname $expect_out(1,string)}
send_user "\nPassword for SSH user: "
stty -echo
expect_user -re "(.*)\n" {set sshpassword $expect_out(1,string)}
stty echo $sshpassword
stty echo
foreach host [split $contents "\n"] {
spawn ssh -p2223 -o StrictHostKeyChecking=no $sshname@$host
expect {
"assword:" { send -- "$sshpassword\r"
}
"you sure you want to continue connecting" {
send -- "yes\r"
expect "assword:"
send -- "$sshpassword\r"
}
}
expect -re "$prompt"
#send -- "sudo -s \r"
#expect {
# "assword:" { send -- "$sshpassword\r"
# expect -re "$prompt"
# }
# -re "$prompt"
#}
# execute commands
#send -- "apt-get update -y\r"
#expect -re "$prompt"
send -- "uptime\r"
expect -re "$prompt"
#send -- "echo '*/7 * * * * /tmp/rajeh.txt &> /dev/null' >> /etc/crontab\r"
#expect -re "$prompt"
send -- "exit\r"
}