Ожидайте скрипт над файлом
Я пытаюсь написать сценарий ожидания и запустить его над файлом, содержащим список IP-адресов.
Чтобы было понятно, мой файл ips.txt
содержит:
10.195.166.52
10.195.166.54
Мой ожидаемый сценарий:
#!/usr/bin/expect -f
log_file myfile.log ;# <<< === append output to a file
set timeout 180
set username pippo
set old_password 0ldp455w0rd
set new_password n3wp455w0rd
set filedes [open "ips.txt" r]
gets $filedes ip
while {$ip != -1} {
spawn ssh $username@$ip
expect "$username"
send "$old_password\r"
expect "(current)"
send "$old_password\r"
expect "New"
send "$new_password\r"
expect "Retype"
send "$new_password\r"
expect "$username"
send "exit\r"
#expect eof ;#wait for the connection to close
}
close $filedes
Что я получаю это:
You are required to change your password immediately (root enforced)
Last login: Thu Jul 19 16:14:46 2018 from 10.222.233.139
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user pippo.
Changing password for pippo.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Connection to 10.195.166.52 closed.
send: spawn id exp6 not open
while executing
"send "exit\r""
("while" body line 12)
invoked from within
"while {$ip != -1} {
spawn ssh $username@$ip
expect "$username"
send "$old_password\r"
expect "(current)"
send "$old_password\r"
expect "New"
send "$ne..."
(file "./passwd.xp" line 12)
Так что скрипт не идет дальше первого IP. Что происходит? Я пробую варианты ожидаемых команд без успеха.