Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-04-2019, 09:13 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
Help with timeout

hi

my script is pretty much working except for the time out

Code:
# $language = "python"
# $interface = "1.0"

def main():
        crt.Screen.Synchronous = True
with open('/Path/to/file/hosts2') as hosts_:
        for host in hosts_:

                crt.Screen.WaitForString("nfs]# ")
                crt.Screen.Send("ssh -oStrictHostKeyChecking=no root@" + host + '\r')
                crt.Screen.WaitForString("word: ")
                crt.Screen.Send("Mypassword" + chr(13))

                szOutput = crt.Screen.ReadString(["# ","word:","ssh: "], 10)
                #szOutput = crt.Screen.WaitForStrings(["]# ","word:","nfs2 # "], 3)
                index = crt.Screen.MatchIndex

                if(index == 0):
                        crt.Screen.Send("echo timeout0" + chr(13))

                elif(index == 1):
                        crt.Screen.Send("mount /rhelrepo;subscription-manager clean;/rhelrepo/scripts/rleon_fix.sh" + chr(13))
                        crt.Screen.WaitForString("]# ")
                        crt.Screen.Send("exit" + chr(13))

                elif(index == 2):
                        crt.Screen.Send("Password2" + chr(13))
                        crt.Screen.WaitForString("]# ")
                        crt.Screen.Send("mount /rhelrepo;subscription-manager clean;/rhelrepo/scripts/rleon_fix.sh" + chr(13))
                        crt.Screen.WaitForString("]# ")
                        crt.Screen.Send("exit" + chr(13))

                elif(index == 3):
                        crt.Screen.Send("echo timeout" + chr(13))
     
                else:
                        crt.Screen.Send("echo timeout" + chr(13))


main()
I am able to attend the 2nd password if the 1st one fails.

But if the host does not connect or can not resolve and falls back to the prompt

Code:
nfs]#
then it does nothing.

I tried in several sections and the timeout just doesnt continue.

I am also not able to echo the hostname into the error file.

Code:
crt.Screen.Send("echo" + host + ">> error" + '\r')
I am missing something .. but i cant figure out it.

Any help or ideas are welcome.

Last edited by ekoranyi; 02-04-2019 at 09:31 AM.
Reply With Quote
  #2  
Old 02-04-2019, 09:46 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi rleon,

You are currently waiting for the stings:

Code:
"# ","word:","ssh: "
The timeout should be triggered if none of these strings appear for the timeout duration. I believe you're running into a problem where the strings you are waiting for are not specific enough, and are accidentally matching rather than timing out.

With a prompt of "nfs]#", it is possible that you are accidentally matching the string "# " in your ReadString.

Perhaps adding your full prompt to the ReadString and handling the case explicitly will give you better behavior.

Code:
ReadString(["# ","word:","ssh: ", "nfs]#"], 10)


elif(index == 4):
Does handling the case of finding your prompt explicitly give you the needed functionality?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 02-04-2019, 10:13 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
Thanks

i changed the code to

Code:
                szOutput = crt.Screen.WaitForStrings(["# ","word:","mbp:nfs #"], 3)
And it still doesnt work

What i noticed was if i cat a file .. it does continue.

So its falling some where but i cant figure out where.

is there a way i can turn on debugging?
Reply With Quote
  #4  
Old 02-04-2019, 10:26 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
rleon,

To get a better idea of what may be happening I will need to review a log file from a connection attempt.

PLEASE DO NOT POST YOUR LOG TO THE FORUMS!

Can you take these steps and send me the resulting log file for analysis?

Video Link: Trace Options Debug Logging in SecureCRT

- Launch SecureCRT and open SecureCRT's main "File" menu and select the "Trace Options" menu item.

- Open the "File" menu again and choose "Log Session..."
--> Specify a path to your Desktop folder and a name of the log file, such as SCRT_Log.txt.

- Now attempt your connection/script again.

- When the script fails, open SecureCRT's "File" menu and look at the "Log Session" menu item. If it has a check-mark next to it, click on it to turn off logging.

- Go to your Desktop folder and locate the SCRT_Log.txt file. Please send the SCRT_Log.txt file to me as an attachment via email. Please don't paste the contents into the body of your message -- please attach it! Send the email to Support@VanDyke.com with "Attn: Eric Forum Post 13388" in the subject line.

It would also be beneficial to include a copy of your full script. You will likely need to rename the script to end in .txt before sending it to ensure it get delivered.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 02-04-2019, 10:34 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 110
I figured out what the issue is but i don't know how to fix it .


In my top block
Code:
               
crt.Screen.WaitForString("nfs]# ")               
crt.Screen.Send("ssh -oStrictHostKeyChecking=no root@" + host + '\r')                
crt.Screen.WaitForString("word: ")                
crt.Screen.Send("Mypassword" + chr(13))
I am waiting for word from the host i am connecting to.

Code:
crt.Screen.WaitForString("word: ")
Since it times out .. fails I never get word - therefore it never goes into the if statements.

Would the only fix be to do another if statement?
Reply With Quote
  #6  
Old 02-04-2019, 01:26 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi rleon,

It looks like you were working with my co-worker Brittney in this thread. She has provided a link to an updated example script that may fit your needs.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:24 AM.