• Support
  • Articles
  • Resources
  • Products

Macro for SSH

Moderator: boris

  • 1
  • 2

33 postsPage 1 of 2

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Mon May 14, 2007 3:37 pm
My question is i'm trying to run a .ttl with SSH. What i want this to do is login and do major changes to Enterasys Routers (over 400). I have made one for telnet but the code is not recognized when i use SSH. I want to have a pool of IP address and once it gets done with one router it goes to the next and the next and so on. here is my code for telnet. Please Help!!!

Code: Select all

  1. ; Sample macro for Tera Term;  Telnet login
  2.  
  3. ; start logging to confirm it worked
  4. logopen 'enterasysresults.log' 1 0
  5.  
  6. ; open txt file of ip numbers
  7. fileopen fhandle 'ipnum' 0
  8. ; if EOF close file
  9. if result goto fclose
  10.  
  11. ; setup looping routine
  12. :loop
  13.  
  14. ;read ip file until EOF
  15. filereadln fhandle openip
  16. if result goto fclose
  17.  
  18. ;  connect Tera Term to ip
  19. connect openip
  20.  
  21.  
  22. ;append to logfile until script is complete
  23. logopen 'enterasysresults.log' 1 1
  24.  
  25. ; set username & pw prompts & values
  26. UsernamePrompt = 'Username:'
  27. Username = 'XXXXXXXXX'
  28.  
  29. PasswordPrompt = 'Password:'
  30. Password = 'XXXXXXX'
  31. Finiprompt = 'Matrix E7 Platinum(su)->'
  32.  
  33. ; login
  34. wait   UsernamePrompt
  35. sendln Username
  36.  
  37. wait   PasswordPrompt
  38. sendln Password
  39.  
  40. ; OK, login complete.
  41. ; setup defaults & clrscreen
  42. timeout = 1
  43.  
  44. ; wait for prompt & send commands...
  45. wait Finiprompt
  46. sendln 'en'
  47. sendln 'show run'
  48. sendln ' '
  49. sendln ' '
  50. sendln ' '
  51.  
  52. ;this line should wait for prompt again & then continue
  53. ;but it appears the timeout is expiring instead
  54. waitln Finiprompt
  55.  
  56. ; go to next ip
  57. logwrite #13#10#13#10
  58. logwrite openip
  59. logwrite ' done'#13#10
  60. logclose
  61. closett
  62.  
  63. goto loop
  64.  
  65. :fclose
  66. fileclose fhandle


:?

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Mon May 14, 2007 3:54 pm
Check the following 2 threads to find the answers on your questions:
http://logmett.com/forum/viewtopic.php?t=449
http://logmett.com/forum/viewtopic.php?t=28
Thanks.
Best regards,
Boris
thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Mon May 14, 2007 4:07 pm
I tried that code and changed it to SSH and it still couldnt recognize it.

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Mon May 14, 2007 4:17 pm
Could you please explain what do you exactly mean by "the code is not recognized" ?
Have you tried to enter all your commands "by hand" ? Did they work?

Paste here the output of your screen, that will give us better idea of what is the issue.
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Mon May 14, 2007 4:28 pm

Code: Select all

  1. connect 'openip :22'  ; not sure of the syntax here or what to connect 2
  2. wait 'Username:'
  3. sendln 'XXXX'
  4. wait 'Password:'
  5. sendln 'XXXXXXX'
  6. wait 'hostname>'
  7. sendln 'ssh 10.3.0.254'
  8.  
  9.  
  10. fileopen filehandle 'ip.txt' 0
  11. filereadln filehandle line
  12.  
  13. while result=0
  14.  connect_line='ssh '
  15.  strconcat connect_line line
  16.  sendln connect_line
  17.  wait 'Username:'
  18.  sendln 'xxxxx'
  19.  wait 'Password:'
  20.  sendln 'xxxxx'
  21.  timeout = 1
  22.  sendln 'en'
  23.  
  24.  filereadln filehandle line
  25. endwhile
  26.  
  27. fileclose filehandle
  28.  
  29. exit


I am not sure what to connect to. Also i don't want to type in the username and password.

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Mon May 14, 2007 4:41 pm
Your connect string does not look right to me. Let's take 1 step a time.

Create new macro and add the followig line:

Code: Select all

  1. connect 'myserver /ssh /2 /auth=password /user=username /passwd=password'


Replace myserver with your server name or IP address. Replace username with actual username and password (at the end of the line) with actual password. Do not change /auth=password part of the string. Are you able to connect using this syntax ?
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Mon May 14, 2007 4:51 pm
when i put an IP in there, from one of our routers i get an error says SSH2 autologin error. If i go to the main menu and type it it works. so something with the autologin is breaking the macro

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Mon May 14, 2007 5:03 pm
When logging in interactive mode do you use plain password to log in (phassphrase), RSA/DSA key or challenge/response option?
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Tue May 15, 2007 1:15 pm
I use plaintext. we have a standard word we use. i downloaded teraterm from http://ttssh2.sourceforge.jp/ where i click the icon on the bottom right corner and go to list configuration and i add some of our sites into and i put ssh and put the passphrase in it and then try and execute it it just has ssh 2.0.0.0 on the screen.

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Tue May 15, 2007 2:13 pm
i click the icon on the bottom right corner

Are you talking about LogMeTT application?

Could you try to start ttermpro.exe from TeraTerm installation directory, then in New Connection window enter your IP address, select service SSH, select SSH version SSH2, make sure that TCP port is set to 22 and click Ok. Another window will show up where you will need to enter your username and password. Could you please do this "pure" test and let us know if it works.
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Tue May 15, 2007 2:16 pm
The pure test works. When i add a new one i have to store the key and all the but once its in there it works fine. I was talking about the TeraTerm Menu on the bottom right corner.

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Tue May 15, 2007 2:21 pm
TeraTerm Menu is old application that is not supported any more (as far as I know). You can do the same and much more using my LogMeTT tool. It is part of TeraTerm package. Check LogMeTT help file to learn about it.
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Tue May 15, 2007 5:08 pm
Do you know why the autologin fails? And the version of tera term might not be any good now a days. Thanks,

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Tue May 15, 2007 5:23 pm
Install the latest version 4.52 and try again http://logmett.com/freeware/TeraTerm/ ... f8_452.exe
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Tue May 15, 2007 5:54 pm
Unfort. same thing. It looks like its working and then it says autologin fails. I can send you my script i have used for telnet and it works like a charm. Just can't get it to work for SSH because the autologin and i think the RSA Key needs to be in the ssh_known_hosts section before it can work with every IP correct me if i'm wrong

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Wed May 16, 2007 1:25 pm
You need to ssh to each server in interactive mode at least once to accept the keys. After that your macro should work. Make sure that remote node accepts SSH (port 22 is listening) and you are using correct ssh mode (SSH1/SSH2)
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Wed May 16, 2007 1:32 pm

Code: Select all

; Sample macro for Tera Term

; start logging to confirm it worked
logopen 'enterasysresults.log' 1 0

; open txt file of ip numbers
fileopen fhandle 'ssh_known_hosts' 0
; if EOF close file
if result goto fclose

; setup looping routine
:loop

;read ip file until EOF
filereadln fhandle openip
if result goto fclose

;  connect Tera Term to ip
connect '182.xxx.xxx.xxx /ssh /2 auth=password user=xxxxx passwd=xxxxx'  <<<<<After this i get the autologin error

;append to logfile until script is complete
logopen 'enterasysresults.log' 1 1


; OK, login complete.
; setup defaults & clrscreen
timeout = 1

; wait for prompt & send commands...
wait Finiprompt
sendln 'en'
sendln 'show run'
sendln ' '
sendln ' '
sendln ' '

;this line should wait for prompt again & then continue
;but it appears the timeout is expiring instead
waitln Finiprompt

; go to next ip
logwrite #13#10#13#10
logwrite openip
logwrite ' done'#13#10
logclose
closett

goto loop

:fclose
fileclose fhandle

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Wed May 16, 2007 1:47 pm
Create new macro, add one line

Code: Select all

connect '182.xxx.xxx.xxx /ssh /2

then manually enter username and password in popup window and check if it will work.
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Wed May 16, 2007 1:50 pm
That works when i type everything in manually but when i try for the autologin it fails. When i do it manually how do i get back to my script?

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Wed May 16, 2007 1:54 pm
Does your password contain @ or space?

Important note: The password can contain space character. To represent space inside the password replace it with @ character. If @ character itself is part of the password than it has to be replaced with 2 consecutive @ characters @@.
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Wed May 16, 2007 4:24 pm
I do have a @ sign but when i try to put @@ where the @ sign is it still fails. I changed the password and took out the @ and it works!!!!!!!!

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Wed May 16, 2007 4:33 pm
Yutraka, maya:

Could you please double check the code to make sure @ and space in passwords work as described in the Important note of this topic: http://logmett.com/forum/viewtopic.php?t=28
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Wed May 16, 2007 4:37 pm
connect 'xxx.xxx.xxx.xxx:22 /ssh /auth=password /user=admin /passwd=Callaw@@y'

Correct syntax? If so this is the code that fails.

 

boris
Moderator, LogMeTT and TTLEditor developer

Posts:
1591
Joined: Sat Jan 08, 2005 2:52 pm
by boris » Wed May 16, 2007 5:00 pm
Looks correct to me. :?
Thanks.
Best regards,
Boris

 

thrdbseshwcase3
Newbie

Posts:
17
Joined: Mon May 14, 2007 3:30 pm
by thrdbseshwcase3 » Wed May 16, 2007 6:23 pm
Once i have connected to the router how am i able to send lines

connect 'xx.x.xx.xxx:22 /ssh /auth=password /user=xxx /passwd=xxxx'

sendln 'en'

Once im in the router i want to start sending command and i know the syntax is not correct i do not believe
Display posts from previous:
Sort by:
  • 1
  • 2

33 postsPage 1 of 2

Users browsing this forum: No registered users