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 09-14-2012, 04:12 AM
Arash Arash is offline
Registered User
 
Join Date: Sep 2012
Posts: 9
Python Login script

Hey!

I'm quite the newbie at scripting so please help me improve my skills a bit.
My goal with this script is to check what output i get after ive entered my username when telneting into a tacacs device.
If the output i get is "Enter PASSCODE: ", I want it to send my 4digit PIN, if I get any other output, it should send my preset password.

This is my current script, it might look silly to some of you, please tell me what i'm doing wrong:


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

import os
import SecureCRT

username = "myusername"
passcode = "1111"
password = "mypass"
pc = "Enter PASSCODE: "

def Main():


crt.Screen.Send(username + "\r")
crt.Screen.WaitForString("Enter PASSCODE: ")
stringpc = crt.Screen.WaitForString("Enter PASSCODE: ")

if "Enter PASSCODE: " in stringpc:
crt.Screen.Send("pc")

else:
crt.Screen.Send(password + "\r")




Main()
Reply With Quote
  #2  
Old 09-14-2012, 07:49 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Arash,

When using Python, code format is vital to the successful writing and running of a script.

Would you please post your script code in a code block so the formatting is retained?

You can wrap your code in a code block by selecting the code, and then pressing the hash (#) icon above, third from the left when making a post.

When you run your script what behavior do you get?

Do you see any errors when running your script?

If you want to improve your Python scripting skills, I would recommend reading the Python documentation at the following location:
http://docs.python.org/
It is a resource I use extensively when writing Python scripts. There are also many sites on the net that have examples illustrating how one can accomplish certain tasks using Python.

Additionally, with regards to the SecureCRT API, we have published a scripting manual that illustrates how to use it at the following location:
http://vandyke.com/support/tips/scripting/index.html
The examples are in VBScript, but most of the SecureCRT API concepts presented apply to most languages.

Without knowing the actual format of your code, my guess is that your script is failing because you did not set the Synchronous property in the Screen object to True prior to interacting with the remote device.

This concept is covered in chapter 4.2 on page 39 of the scripting manual.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 09-14-2012, 07:58 AM
Arash Arash is offline
Registered User
 
Join Date: Sep 2012
Posts: 9
script

Hi. thanks for your post. I dont get any errors while running this script but i dont get any output from it other than my username.


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

import os
import SecureCRT

username = "myusername"
passcode = "1111"
password = "mypass"
pc = "Enter PASSCODE: "



def Main():

	
	crt.Screen.Send(username + "\r")
	crt.Screen.WaitForString("Enter PASSCODE: ")
	stringpc = crt.Screen.WaitForString("Enter PASSCODE: ")
	
	if "Enter PASSCODE: " in stringpc:
		crt.Screen.Send(pc)
	
	else: 
		crt.Screen.Send(password + "\r")
	
	
	

Main()
Reply With Quote
  #4  
Old 09-14-2012, 08:28 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Arash,

Thanks for posting your script in a code block.

From my previous post:
Quote:
Without knowing the actual format of your code, my guess is that your script is failing because you did not set the Synchronous property in the Screen object to True prior to interacting with the remote device.

This concept is covered in chapter 4.2 on page 39 of the scripting manual.
Does this help you resolve the issue?

If not, would you let me know how you are invoking this script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 09-14-2012, 08:40 AM
Arash Arash is offline
Registered User
 
Join Date: Sep 2012
Posts: 9
1

Hi again. Synchronous in screenobject didn't help.
I invoke the script by running it after ive telneted to the device, (pushing the keybinding that i mapped the script to)
Reply With Quote
  #6  
Old 09-14-2012, 08:47 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Arash,

Thanks for the update. When making code changes, it is helpful if you post the code each time a change is made.

Would you post the code that you are now using that is failing?

How is the code failing?
__________________
--Todd

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 09:37 AM.