I am writing an expect script which sshs into some special network devices and grab some files.
When i manually run it there is not problem at all, but when I put the same expect script into cron, i get randomly "EOF" being sent from the device as soon as the passwd gets sent to the device.
Can anyone take a look at my script and tell me what should i do to make the cron work?(i tried to set the term type and did not work)
The core part of the expect script looks like this,
while {[gets $list line] != -1} {
spawn ssh -t admin@$line
expect {
"password:" {
send "$password\r"
expect "admin"
send "shell\r"
expect {
"ksh" {
send "cat /tmp/status.txt\r"
expect "commands"
send "exit\r"
expect "admin"
send "exit\r"
}
eof {wait}
}
}
timeout {break}
}
}
and the error message is like this:
expect: does "@06:/# " (spawn_id exp13) match glob pattern "ksh"? no
shell
expect: does "@06:/# shell\r\n" (spawn_id exp13) match glob pattern "ksh"? no
Connection to a.b.c.d closed.
expect: does "@a.b.c.d:/# shell\r\nConnection to a.b.c.d closed.\r\r\n" (spawn_id exp13) match glob pattern "ksh"? no
expect: read eof
expect: set expect_out(spawn_id) "exp13
When i manually run it there is not problem at all, but when I put the same expect script into cron, i get randomly "EOF" being sent from the device as soon as the passwd gets sent to the device.
Can anyone take a look at my script and tell me what should i do to make the cron work?(i tried to set the term type and did not work)
The core part of the expect script looks like this,
while {[gets $list line] != -1} {
spawn ssh -t admin@$line
expect {
"password:" {
send "$password\r"
expect "admin"
send "shell\r"
expect {
"ksh" {
send "cat /tmp/status.txt\r"
expect "commands"
send "exit\r"
expect "admin"
send "exit\r"
}
eof {wait}
}
}
timeout {break}
}
}
and the error message is like this:
expect: does "@06:/# " (spawn_id exp13) match glob pattern "ksh"? no
shell
expect: does "@06:/# shell\r\n" (spawn_id exp13) match glob pattern "ksh"? no
Connection to a.b.c.d closed.
expect: does "@a.b.c.d:/# shell\r\nConnection to a.b.c.d closed.\r\r\n" (spawn_id exp13) match glob pattern "ksh"? no
expect: read eof
expect: set expect_out(spawn_id) "exp13