Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-07-2017, 09:24 AM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
if statement help ,

Running the latest secureCRT on MAC.

Code:
                objNewTab.Screen.WaitForString("# ")
                objNewTab.Screen.Send("ssh " + host + '\r')
                objNewTab.Screen.WaitForString("word: ")
                objNewTab.Screen.Send("mypass" + chr(13))

                if objNewTab.Screen.WaitForString("word: "):
                        objNewTab.Screen.Send(chr(3))
                        objNewTab.Screen.WaitForString("# ")
                        objNewTab.Screen.Send("ssh " + host + '\r')
                        objNewTab.Screen.WaitForString("word: ")
                        objNewTab.Screen.Send("mypass" + chr(13))
                        objNewTab.Screen.WaitForString("$ ")
                        objNewTab.Screen.Send("su - root" + chr(13))
                        objNewTab.Screen.WaitForString("word: ")
                        objNewTab.Screen.Send("mypass" + chr(13))
                        objNewTab.Screen.WaitForString("# ")
                        objNewTab.Screen.Send(chr(13))
                ##else:
                if objNewTab.Screen.WaitForString("# ") :
                        objNewTab.Screen.Send(chr(13))
                        objNewTab.Screen.WaitForString("# ")
                        objNewTab.Screen.WaitForString("echo test" + chr(13))
                        objNewTab.Screen.Send(chr(13))
I have this peice of code , I copied it from other sample scripts and modified as needed.
Issue is i cant get it to drop into the second part
I have tried else , elif, if not with no luck.

Code:
              ##else:
                if objNewTab.Screen.WaitForString("# ") :
                        objNewTab.Screen.Send(chr(13))
Reply With Quote
  #2  
Old 03-07-2017, 12:47 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi rleon,

When you say you can't get it to drop into the second part do you mean after:

Quote:
if objNewTab.Screen.WaitForString("# ") :
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-08-2017, 02:06 PM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
Hi ekoranyi

That is correct

I tried elsif if .. if not , == true and nothing works.

Code:
if objNewTab.Screen.WaitForString("# ") :
Reply With Quote
  #4  
Old 03-08-2017, 03:38 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
rleon,

What language are you using?

What are you trying to accomplish?

Does the WaitForString in the second to last line of the first block seem to work as desired?
Quote:
objNewTab.Screen.WaitForString("# ")
objNewTab.Screen.Send(chr(13))
Have you tried simply using the equivalent of EndIf so that the second part is a separate If statement?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 03-10-2017, 07:20 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
When you need to perform a branch based on "thingA" vs "thingB" arriving from the remote, you cannot do so using nested WaitForString() calls. You must use WaitForStrings() instead, using the Screen's MatchIndex property to determine which of your strings was found.
When something like "thingA" has already shown up on the screen, it's too late to call WaitForString("thingA"); "thingA" has already arrived, been displayed to the screen, and cannot be WaitForString'd.
In your case, you'll need a construct that uses WaitForStrings to wait for all possible things that you need to branch on, as exemplified in the posted example in the scripting "sticky": Example: Jump Host - Handle Secondary Host Connection Attempts

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply

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 07:56 AM.