Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/expect-logic.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
expect logic

Posted by pret (pret), 3 January 2006
hi iam new to expect infact new to scripting

set PING "ping"

proc newpingDev { newipAddr } {
       global PING PING_TIMEOUT


            exp_send --   "$PING $newipAddr\r"
             # spawn ping $newipAddr\r
       while (1) {
               expect {
                       "*bytes from * time*"  {
                               return "SUCCESS"
                       }
                       "*is alive*"  {
                               return "SUCCESS"
                       }
                       "*Destination Host Unreachable*"  {

                              return "FAILED"
                       }
                       "*Network is unreachable*"  {
                                                                                      return "FAILED"
                       }
                       "*no answer from*"  {
                               return "FAILED"
                       }
                       "unknown host" {
                              return "FAILED"
                       }
                       "*Usage*"  {
                               return "FAILED"
                       }
                       timeout {
                              return "FAILED"
                       }
               }
       }



}


set newip "160.48.58.39"
set devIp "1.1.1.1"

set rval [eval newpingDev $devIp]
puts " the return value from newiptest is $rval"


if { $rval == "FAILED" } {
    set _rval [eval newpingDev $newip]
    puts " the return value from newiptest is $_rval"


}


the new ip is pingabble and devip is dummy ip so when i i run the script
with send  its says both the ip are not pingable and returns failed where
as when i use spawn ping ipadrres in the function i could ping the second ip   why i sthis happ.i need to use send command instead of spawn
.canu pls help ..this is a test program  my real program is when the first ping failed to ping address then it should ping then next one but when i use send command thats not working

i telnet in to multiple device and pipng it so after telnet i cannot spawn a ping sesssion so i need to use a send command but its not working ..any help pls


Posted by admin (Graham Ellis), 4 January 2006
1. You say "it's not working".  Can you tell us what actually happens  as that will give a further clue as to what is going wrong.

2. You mention telnet, but I don't see any spawn of a telnet - perhaps the program you've posted is incomplete?   If you could come up with a short, complete example showing what's going wrong we might be able to help you a little better.

Use spawn to start a process, then send and expect to communicate with it; if you don't start off with a spawn, you can't send or expect.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho