Jump to content

Planning for ssh connection


 Share

Recommended Posts

Hello everyone.

I'm hoping to write a script that does

1. plink --ssh x.x.x.x

2. if output is ("do you want to add this to the permanent.."), send ("y")

3. if output is ("login"), send ("administrator")

4. if output isn't ("password"), report error. if it is, send password

5. if output is ("login") AGAIN, send ("administrator") again

.

.

6. attempt to cd to a directory(ex. cd d:\program files\dir)

7. if output is ("d:\program files\dir>") send commands

8. else try another directory(ex. cd d:\program files\dir2)

.

.

9. run a command once I found a correct directory

10. wait for up to 30 seconds for output "success". congratulate the user if we get it, report error otherwise.

Now, I'm running into problems all over the place.

1. Run() command is more complicated than I thought. Does "run("cmd /k plink --ssh x.x.x.x", '', @SW_SHOW, 7) sound good?

2. How do I deal with multiple choice? After running the initial command, I expect to receive one of many commands and act appropriately. What would be a clean way to have many of these clauses in an orderly fashion? This includes StdOut and StdErr mess as well.. =/

AutoIt seems to be more complicated than I thought..

Link to comment
Share on other sites

By "plink" I shoud understand that you're using PuTTY for this task.

I never worked with PuTTY because it wouldn't allow me to use it over COM1 but I worked with Tera Term which is a similar software.

I guess with PuTTY is the same situation (you can't identify the control ID for the main window).

I made a script to connect to network switches via COM1 or Telnet or SSH and it is using Tera Term. the only way I found to get the window text was to use the "log" ability and to read that file real-time. PuTTY should have a log mode also. I tried to use the MS Telnet (with log) and I found that the last line (the prompt line ... which is the most important) it is not showed into its log file ... so I had to give up on that.

The first part - regarding running PuTTY and accepting to add the IP in the list is the easiest to do - you will need to use a simple Run command; for accepting ... you will need to send either an "ENTER" or an Alt Something ... (the "Send" command)

The next part is hardest. you will need to get the window text and to use "StringInStr" command to look for certain keywords (if it finds "login" then send "administrator", if it finds "password" then send the password. You will need to continuously read that log file in order to determine which is the answer returned and what you should do in that case (the answer could be like a succes - when you get the prompt or an error message)

I will do my best to help you with advices or code debug whenever you need.

about this:

run("cmd /k plink --ssh x.x.x.x", '', @SW_SHOW, 7)

it would be better to use like:

Run ("C:\Program Files\Putty\plink.exe --ssh x.x.x.x")
just be sure that the path to plink is the correct one. Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

run("cmd /k plink --ssh x.x.x.x", '', @SW_SHOW, 7)

vs

Run ("C:\Program Files\Putty\plink.exe --ssh x.x.x.x")
just be sure that the path to plink is the correct one.
My intention behind cmd /k was to keep the window opened after the command completes. Is there a way to achieve this using your example?

Also, what happends to StdErr if you don't specify the io flag 7?

Edited by CSP
Link to comment
Share on other sites

My intention behind cmd /k was to keep the window opened after the command completes

ahhh ... so this plink is not like an independent terminal software (it has its own window ... and stuff) ... sorry - I thought it was. :rolleyes:

I'm affraid that I won't be able to help you too much in this case - you will need help to get the text from the DOS window and analize it ...

HerewasPlato gave a link to someone asking for that ... I might be able to find it ..

http://www.autoitscript.com/forum/index.php?showtopic=48522

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...