Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > SecureCRT on the Mac

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 07-05-2017, 12:32 PM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
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()
Reply With Quote
  #2  
Old 07-05-2017, 01:34 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
  #3  
Old 08-23-2017, 02:53 PM
rleon rleon is offline
Registered User
 
Join Date: Jan 2008
Posts: 116
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))
This is the command I am trying to run on several hundred hosts . i would like to automate it.

Code:
ssh -oStrictHostKeyChecking=no root@$host "hostname;cat /etc/redhat-release" >> out.tmp

Last edited by rleon; 08-23-2017 at 03:02 PM.
Reply With Quote
  #4  
Old 08-23-2017, 03:10 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
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
Reply With Quote
Reply

Thread Tools
Display Modes

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 10:38 AM.