Macro for SSH
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Wed May 16, 2007 6:25 am 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
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


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:32 am 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
; 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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:47 am 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
Create new macro, add one line
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


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:50 am 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
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?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:54 am 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
Does your password contain @ or space?

Quote:
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


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 9:24 am 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
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!!!!!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 9:33 am 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
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


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 9:37 am 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
connect 'xxx.xxx.xxx.xxx:22 /ssh /auth=password /user=admin /passwd=Callaw@@y'

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 10:00 am 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
Looks correct to me. :?

_________________
Thanks.
Best regards,
// Boris


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 11:23 am 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 11:46 am 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
I'd suggest you to add setsync 1 next to your connect command. Then if there is no branching involved you just do wait then sendln, then wait again etc. Usually argument of wait is the command prompt text.

_________________
Thanks.
Best regards,
// Boris


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 11:55 am 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
Could you give me an example?

I want to do a en (sendln 'en')
(sendln 'sh run')
I put setsync 1 next to it and still couldnt get it


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 12:14 pm 
Offline
Moderator, LogMeTT developer
User avatar

Joined: Sat Jan 08, 2005 7:52 am
Posts: 1143
Location: Seattle, WA, USA
connect 'your connect line here'
setsync 1
wait 'whatever prompt you get on the screen once you connected'
sendln 'en'
wait 'probably the same prompt as above'
sendln 'sh run'
wait 'whatever prompt will be after running the script  run'
; the rest of your macro

_________________
Thanks.
Best regards,
// Boris


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed May 16, 2007 12:52 pm 
Offline
Newbie

Joined: Mon May 14, 2007 8:30 am
Posts: 17
here is what i have and is working. What i want to do is have it execute what i put and grab another IP form a list instead of writing them out like this

connect 'xxx.xxxx.xxx.xxx22 /ssh /auth=password /user=net /passwd='
xxxxx
Enable = 'en'
ShowRun = 'show run'
Config = 'config'

mpause 3000

sendln Enable
sendln ShowRun
sendln ' '
sendln ' '
sendln ' '

mpause 5000

unlink

mpause 5000
connect 'xxxx.xxx.xxx.xx:22 /ssh /auth=password /user=net/passwd=xxxxx'

Enable = 'en'
ShowRun = 'show run'
Config = 'config'

mpause 3000

sendln Enable
sendln ShowRun
sendln ' '
sendln ' '
sendln ' '


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 6:22 am 
Offline
Guru

Joined: Wed Jan 25, 2006 7:28 pm
Posts: 532
Location: Denver, Colorado, USA
Something like this?

fileopen fh "c:\tmp.txt" 0
filereadln fh line
while result=0
    mpause 5000
    strconcat line ':22 /ssh /auth=password   user=net/passwd=xxxxx'
    connect line

    Enable = 'en'
    ShowRun = 'show run'
    Config = 'config'

    mpause 3000

    sendln Enable
    sendln ShowRun
    sendln ' '
    sendln ' '
    sendln ' '
    unlink
    filereadln fh line
endwhile


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group