|
#1
|
|||
|
|||
run ssh command
I am trying to ssh in .. and run the uptime command .. in my loop.
I am missing something i cant run the uptime command or any other strings. def main(): crt.Screen.Synchronous = False with open('/crt_scripts/working/hosts') as hosts_: for host in hosts_: crt.Screen.WaitForString("working # ") crt.Screen.Send("ssh -oStrictHostKeyChecking=no root@" + host + uptime + '\r') crt.Screen.WaitForString("word: ") crt.Screen.Send("mypass" + chr(13)) main() |
#2
|
|||
|
|||
Hi rleon,
It appears that your sequence of events may be off. It appears you are waiting for "working # " before you even connect to the remote device. When/how is "working # " appearing on screen? If this does not appear on screen or appears prior to the waitforstring your loop will never progress. Next I see ("ssh -oStrictHostKeyChecking=no root@" + host + uptime + '\r') which appears to be a connection attempt, what is the uptime variable and why is it being appended to the ssh connection attempt? Then I see an attempt to authenticate. Typically the sequence would be more like: 1) Attempt Connection 2) Wait for password prompt 2) Send password when prompted 3) Wait for confirmation authentication succeeded 5) Send uptime command
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
This is on my MAC - I want to make sure i get my local prompt before I execute.
Code:
crt.Screen.WaitForString("working # ") I didn't realize that it was reading uptime as variable .. uptime is a command that I want ran. Since I do not have ssh keys set up .. i get a prompt for the password hence the promot and then i send the password to execute the command remotely. Code:
crt.Screen.Send("ssh -oStrictHostKeyChecking=no root@" + host + uptime + '\r') crt.Screen.WaitForString("word: ") crt.Screen.Send("mypass" + chr(13)) Code:
ssh -oStrictHostKeyChecking=no root@$host "hostname;cat /etc/redhat-release" >> out.tmp Last edited by rleon; 08-23-2017 at 03:02 PM. |
#4
|
|||
|
|||
Hi rleon,
It appears you are attempting to connect to a list of hosts and to run the uptime command on each, is that correct? If so we may have a sample script you would be interested in. It demonstrates how to connect to hosts read in from a "hosts" file and for each host, send a list of commands read in from a "commands" file. Results of each command run are (by default) logged to separate, uniquely-named files based on the host address and the command that is run. However, the script code is architected to allow you to change this behavior so that it's all logged to one file per host, or even just to a single file.
__________________
Thanks, --Eric VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Thread Tools | |
Display Modes | |
|
|