INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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

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

(OP)
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
            
     }

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close