Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help diagnose errors: sync byte read: bad file number...

Status
Not open for further replies.

LilTCLer

Programmer
Nov 27, 2007
37
US
Can anyone help me determine the cause of the following errors?

I have a script that I use to telnet into several DUTs, execute a "show" command to grab some data, write the data to a single file, the close the spawned telnet process. The script will loop indefinitely; however, the foolowing errors are observed about an hour or so into execution and it obviously stops.

TIA

Attempting to connect to: 172.23.130.37
spawn telnet 172.23.130.37 4083
parent: sync byte read: bad file number
child: sync byte write: bad file number
 
Here is the script that I am using in case this helps. I'm stumped.

proc getTime { } {

set TM [clock format [clock second] -format %H%M]
set hour [clock format [clock second] -format %H]
set minute [clock format [clock second] -format %M]
set second [clock format [clock second] -format %S]
set month [clock format [clock second] -format %m]
set day [clock format [clock second] -format %d]
set year [clock format [clock second] -format %y]
set DAT [clock format [clock second] -format %m%d%y]

set timeOfDay "${hour}:${minute}:${second}"
set date "${month}-${day}-${year}"
return "$timeOfDay $date"

}

proc cliConnectSession { systemSID targetSystemIP shelfUnderTest } {

set port 4083

spawn telnet $targetSystemIP $port
set id $spawn_id
set timeout 15

expect {
"$systemSID" {
puts "\n\n"

exp_send -s -i $id "\r"
sleep 1
expect -i $id "$systemSID- Login:" {}
exp_send -s -i $id "Admin1\r"
sleep 1
expect -i $id "$systemSID- Password:" {}
exp_send -s -i $id "12345$\r"
expect -i $id "$systemSID- Enter The Packet Shelf Number" {}
exp_send -s -i $id "$shelfUnderTest\r"
expect {
-i $id "$shelfUnderTest*-$systemSID-$shelfUnderTest" { }
-i $id "$shelfUnderTest*Shelf is not a Packet Shelf" { close -i $id; wait; return 99 }
-i $id "$shelfUnderTest*Could not connect to Active Shelf Controller Module*" { close -i $id; wait; return 99 }
-i $id "$shelfUnderTest*Maximum number of sessions has been reached on the shelf. Try again later*" { close -i $id; wait; return 99 }
-i $id "$shelfUnderTest*Connection to $targetSystemIP closed by foreign host." { close -i $id; wait; return 99 }
timeout { puts "TimedOUT"; close -i $id; wait; return 99 }
}
return $id
}

"Unable to connect" {
return 98
}
timeout {
return 98
}
}

}

################################################################################
# MAIN
################################################################################



set send_slow {1 .01}
set TM [clock format [clock second] -format %H%M%S]
set DAT [clock format [clock second] -format %m%d%y]

match_max 7000


keylset systemList COSTANZA.name "COSTANZA" COSTANZA.ipaddress "172.23.130.33" COSTANZA.shelfUnderTest "5"
keylset systemList SEINFELD.name "SEINFELD" SEINFELD.ipaddress "172.23.130.36" SEINFELD.shelfUnderTest "5"
keylset systemList NEWMAN.name "NEWMAN" NEWMAN.ipaddress "172.23.130.38" NEWMAN.shelfUnderTest "5"
keylset systemList UNCLE_LEO.name "UNCLE_LEO" UNCLE_LEO.ipaddress "172.23.130.39" UNCLE_LEO.shelfUnderTest "5"
keylset systemList UNCLE_LEO_HCSS.name "UNCLE_LEO" UNCLE_LEO_HCSS.ipaddress "172.23.130.39" UNCLE_LEO_HCSS.shelfUnderTest "3"
keylset systemList KRAMER.name "KRAMER" KRAMER.ipaddress "172.23.130.37" KRAMER.shelfUnderTest "2"


set logFileName "/vobs/automation/misc/systemUse_${TM}_${DAT}.log"
if [catch { open $logFileName w+ 0777 } file ] {
puts stderr "\n\nCannot open $logFileName : $file"
}
puts $file "\n\n\n SYSTEM USAGE LOG\n\n\n"

while 1 {


for { set index 0 } { $index < [ llength [ keylkeys systemList ] ] } { incr index } {


set sysTem [ lindex [ keylkeys systemList ] $index ]
set sid [ keylget systemList $sysTem.name ]
set shelf [ keylget systemList $sysTem.shelfUnderTest ]
set prompt "${sid}-${shelf}"
puts $file "$sysTem"
puts $file "TIME: [getTime]"

puts "Attempting to connect to: ${sysTem}"

set id [ cliConnectSession [ keylget systemList $sysTem.name ] [ keylget systemList $sysTem.ipaddress ] [ keylget systemList $sysTem.shelfUnderTest ] ]


if { [ string match $id "99" ] } {


puts "\n\n***ERROR connecting to [ keylget systemList $sysTem.name ] CLI***\n\n"
puts $file "STATUS: Unable to Connect to Packet Shelf CLI\n"

} elseif { [ string match $id "98" ] } {

puts "\n\n***ERROR connecting to [ keylget systemList $sysTem.name ] - No TELNET Connection***\n\n"
puts $file "STATUS: Unable to TELNET\n"



} else {
expect -re $
exp_send -s -i $id "show switch\r"
expect {
-i $id "show switch*$prompt" {
set bufferSize [ llength $expect_out(buffer) ]
if { $bufferSize > "19" } {
puts "\n\n*** System is in USE ---> [ getTime ]***\n\n"
puts $file "STATUS: IN USE"
} else {

puts "\n\nSystem is IDLE ---> [ getTime ]\n\n"
puts $file "STATUS: IDLE"
}
close -i $id
wait
}
-i $id "Connection to [ keylget systemList $sysTem.ipaddress ] closed by foreign host." {
}
timeout { puts "TimedOUT" }


}
puts $file "\n"
}

}
puts "\n\nWaiting 5 minutes"
sleep 300

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top