Итак, у меня был скрипт, который подключался к коммутатору и взаимодействовал, или запускал несколько команд и выходил. Ну, я попытался сделать его более безопасным, добавив функцию из другого файла, и теперь все просто не работает. Кажется, что когда функция завершена, сеанс s sh завершается, взаимодействие внутри функции или вне ее не работает, и, конечно, выполнение большего количества команд не проходит хорошо ...
Я был бы признателен некоторые идеи о том, что не так:
1-й скрипт, содержащий функцию [ssssh2]:
#!/usr/bin/expect
proc log-in { host } {
set timeout 20
set passfile [open "~/bin/.l" r]
gets $passfile pass
gets $passfile enab
gets $passfile user
close $passfile
spawn ssh $user@$host
expect -timeout 5 {
"yes/no" { send "yes\r" }
"#" {}
}
expect "word"
send "$pass\r"
expect {
"#" {}
">" {
send "en\r"
expect "word"
send "$enab\r"
}
}
send "\r"
expect "#"
send "terminal length 0\r"
expect "#"
}
Вот скрипт, который его вызывает - на данный момент я хочу взаимодействовать в конце, в других вариации это может быть текущая строка команд переключения, заканчивающаяся выходом из системы. Этот скрипт запускается с -d для отладки [sssh2]
#!/usr/bin/expect -d
source ~/bin/ssssh2
log-in $argv
send "\r"
expect "#"
send "terminal length 50\r"
expect "#"
interact
А вот вывод в режиме отладки:
# sssh2 host***
expect version 5.45
argv[0] = /usr/bin/expect argv[1] = -d argv[2] = /root/bin/sssh2 argv[3] = host***
set argc 1
set argv0 "/root/bin/sssh2"
set argv "host***"
executing commands from command file /root/bin/sssh2
spawn ssh user***@host***
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {3729}
expect: does "" (spawn_id exp7) match glob pattern "\n "yes/no" { send "yes\r" }\n "#" {}\n "? no
host*** Radius Enabled
expect: does "host*** Radius Enabled\r\r\n" (spawn_id exp7) match glob pattern "\n "yes/no" { send "yes\r" }\n "#" {}\n "? no
user***@host***'s password:
expect: does "host*** Radius Enabled\r\r\nuser***@host***'s password: " (spawn_id exp7) match glob pattern "\n "yes/no" { send "yes\r" }\n "#" {}\n "? no
expect: timed out
expect: does "host*** Radius Enabled\r\r\nuser***@host***'s password: " (spawn_id exp7) match glob pattern "word"? yes
expect: set expect_out(0,string) "word"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "host*** Radius Enabled\r\r\nuser***@host***'s password"
send: sending "mypass***\r" to { exp7 }
expect: does ": " (spawn_id exp7) match glob pattern "#"? no
">"? no
expect: does ": \r\n" (spawn_id exp7) match glob pattern "#"? no
">"? no
host***>
expect: does ": \r\n\r\nhost***>" (spawn_id exp7) match glob pattern "#"? no
">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) ": \r\n\r\nhost***>"
send: sending "en\r" to { exp7 }
expect: does "" (spawn_id exp7) match glob pattern "word"? no
e
expect: does "e" (spawn_id exp7) match glob pattern "word"? no
n
Password:
expect: does "en\r\nPassword:" (spawn_id exp7) match glob pattern "word"? yes
expect: set expect_out(0,string) "word"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "en\r\nPassword"
send: sending "mypass2***\r" to { exp7 }
send: sending "\r" to { exp7 }
expect: does ":" (spawn_id exp7) match glob pattern "#"? no
*
expect: does ":*" (spawn_id exp7) match glob pattern "#"? no
*****************
host***#
host***#
expect: does ":******************\r\n\r\nhost***#\r\nhost***#" (spawn_id exp7) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) ":******************\r\n\r\nhost***#"
send: sending "terminal length 0\r" to { exp7 }
expect: does "\r\nhost***#" (spawn_id exp7) match glob pattern "#"? yes
expect: set expect_out(0,string) "#"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "\r\nhost***#"
}end: sending "\r" to { exp0
expect: does "" (spawn_id exp0) match glob pattern "#"? no
expect: timed out
}end: sending "terminal length 50\r" to { exp0 terminal length 50
expect: does "" (spawn_id exp0) match glob pattern "#"? no
expect: timed out
cannot interact with self - set spawn_id to a spawned process
while executing
"interact"
(file "/root/bin/sssh2" line 11)
Я в растерянности здесь ..... Спасибо за любая помощь!
GT