VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Python logging via script (https://forums.vandyke.com/showthread.php?t=11775)

helpme 11-10-2014 10:36 AM

Python logging via script
 
I'm using a python script to automate several things in our environment. When the script runs it seems to send an extra return when trying to sign in. I've used different variations of login methods such as waitforstrings with an array, but it always turns out the same way.

Script excerpt:
for eachDevice in strDevices:

CurrentTab = crt.GetScriptTab()
CurrentTab.Screen.Synchronous = True
CurrentTab.Screen.IgnoreEscape = True
CurrentTab.Screen.Send("telnet " + eachDevice + "\r")
Login = CurrentTab.Screen.ReadString(":")
if Login.find("sername")>-1:
CurrentTab.Screen.Send(Username + "\r")
elif Login.find("ogin")>-1:
CurrentTab.Screen.Send(Username + "\r")

Old code (still happened here and there was a delay too using this code)
#Prompt=["sername:","login:"]
#while True:
#CurrentTab.Screen.WaitForStrings(Prompt)
#CurrentTab.Screen.Send(Username + "\r")
#break

Terminal:
ACS5.5 username:
% Authentication failed (notice how no username is entered)

ACS5.5 username: [username]
ACS5.5 password:

At this point it logs in successfully. The extra return seems to be only when it initially connects.

SecureCRT ver 7.2.5

rtb 11-10-2014 12:23 PM

Hi helpme,

Thanks for the post.

I don't get the extra enter that you are seeing.

Do you get this when connecting to all types of devices or just one type?

If you remove the file and loop in the excerpt and just hard code the device (eachDevice), do you get better behavior?

What operating system are you using?

helpme 11-10-2014 12:46 PM

Thanks, you led me in the right direction. It turned out to be an extra whitespace after some of the devices when reading from the file. I added eachDevice.strip() to solve the problem.

Thanks for your help!

rtb 11-10-2014 01:17 PM

Hi helpme,

Thanks for the update. Your solution was my guess after testing, but I wanted to get more information.

The whitespaces may have been non-printing characters that were throwing things off as well.


All times are GMT -6. The time now is 01:04 AM.