|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
Softpanorama Search
|
| News | Teraterm | Recommended Links | Reference | LogMeTT | |
| Expect | SSH | Password-less SSH login | Telnet protocol | Serial Console on Solaris | sshfs |
| GNU Screen | Exceed HostExplorer | HyperTerm | TTPMenu | Humor | Etc |
Teraterm macro language is documented at MACRO Help Index. Generally you should use version 4.62 or later as there were important additions to macro language in recent versions (starting from 4.52):
2006.2.10 (Ver 4.27)
- added 'mpause' macro command. This command enables the macro script to pause the specified time in millisecond.
- added the sample TTL macro 'mpause.ttl'.
- added 'random' macro command. This command enables the macro script to generate the random value.
- added the sample TTL macro 'random.ttl'.
2006.10.09 (Ver 4.46)
- added 'clipb2var' macro command. This command enables the macro script to get data from clipboard.
- added 'var2clipb' macro command. This command enables the macro script to set data to clipboard.
2007.8.8 (Ver 4.53)
- added ‘tolower’ macro command.
- added ‘toupper’ macro command.
- added ‘break’ macro command.
- added an argument to inputbox macro command. New argument is used for default input string.
- added logical operator "&&", "||", "!" and bitwise operator "&", "|", "^", "~" for macro.
- added "Cygterm Here" to a context menu of Explorer. CygTerm can be started from an any directory on Explorer.
2007.9.30 (Ver 4.54)
- added shift operator ">>", "<<", ">>>" for macro.
- changed the priority of macro operator in the following order:
New:
Priority Operator
1 not ~ ! +(unary) -(unary)
2 * / %
3 + -
4 >> << >>>
5 and &
6 xor ^
7 or |
8 < > <= >=
9 = == <> !=
10 &&
11 ||Old:
Priority Operator
1 not ~ ! +(unary) -(unary)
2 * / %
2 and &
3 + -
3 or xor | ^
4 = <> < > <= >=
5 &&
6 ||
- added 'rotateleft', 'rotateright' macro command.
- added 'setenv' macro command.
- added 'filenamebox' macro command.
2007.12.4 (Ver 4.56)
- added support of handling large text data in clipboard to macro command clipb2var.
- added new argument to macro command clipb2var. It controls start position of copying. if clipboard content is too long and copied string was truncated, clipb2var returns 2 in system variable "result".
- added 'do', 'loop' macro command.
- added 'until', 'enduntil' macro command.
- added 'callmenu' macro command.
- added `screencapture.ttl' file as a sample TTL macro.
2008.1.15 (Ver 4.57)
- added 'cygconnect' macro command.
- added new argument to getdate and gettime macro command. It specifies date and time format.
- added 'scpsend' macro command.
- added 'scprecv' macro command.
2008.6.25 (Ver 4.59)
- added 'strmatch' macro command.
- added 'setrts' and 'setdtr' macro command.
2008.9.23 (Ver 4.60)
- added 'crc32' and crc32file macro command.
- added 'getttdir' macro command.
2009.3.22 (Ver 4.62)
- added `sprintf2' macro command.
- added `waitn' macro command. Special thanks to p3g4asus.
- added the result of "logopen" macro command stores to 'result' variable.
- added "mtimeout" macro variable. When a user uses the wait-related macro, Tera Term waits "timeout
- 1000 + mtimeout" millisecond. Precision is about 50 msec.
- added `sendbroadcast' macro command.
- added `sendlnbroadcast' macro command.
- added `sendmulticast' macro command.
- added `setmulticastname' macro command.
Here is funny a sample program:
; 1. Open Tera Term Pro (free VT100 emulator)
; 2. Control -> Macro
; 3. choose 99b.ttl
;
; it will run even if you close the app, to kill prematurely please open
; taskmanager and kill the ttpmacro.exe
;
; 99 Bottles of Beer macro for Tera Term
; by Lance Yamada
for i 99 1
j = i - 1
int2str istr i
int2str jstr j
strconcat istr ' bottles of beer on the wall,'
strconcat jstr ' bottles of beer on the wall!'
if i = 1 then
messagebox '1 bottle of beer on the wall,' 'Tera Term'
messagebox 'time to get more beer!' 'Tera Term'
else
messagebox istr 'Tera Term'
messagebox 'take one down pass it around,' 'Tera Term'
messagebox jstr 'Tera Term'
endif
next
Several sample ttl file are included with Teraterm but they usually need some minor tweaking before they work with real servers. For example:
; sample macro of Tera Term ; ; File: ssh2login.ttl ; Description: auto login with SSH2 protocol ; Environment: generic ; Update: 2004/12/4 ; Author: Yutaka Hirata username = 'nike' hostname = '192.168.1.3' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; msg = 'Enter password for user ' strconcat msg username passwordbox msg 'Get password' msg = hostname strconcat msg ':22 /ssh /auth=password /user=' strconcat msg username strconcat msg ' /passwd=' strconcat msg inputstr
|
|||||||
Ishmael first of all thank you so much for your time and efforts!
Below you'll find my script, please feel free to comment and to point me where i'm doing wrong
any comments on how to improve are appreciated!
thank you again!
Alessio
P.S. is your nick remotely connected with a David Gerrold Book?
- ;°°°°°°°°°°°°°°° Conf Parameters °°°°°°°°°°°°°
- username='XXXXX' ; username for connection
- password='YYYYYY' ; password for connection
- ip_address='IP_TEST.txt'; file with ip addresses of the routers to analyze
- timeout=5; timeout
- Sedi='indirizzi.txt'; file containing results
- ;°°°°°°°°°°°°°°°° APERTURA FILE CONTENENTE IP °°°°°°°°°
- ; Opening file with addresses
- fileopen fhandle Ip_address 0
- filecreate fh Sedi
- ;°°°°°°°°°°°°°°°° INIZIO LOOP °°°°°°°°°°°°°°°°°°°°°°°°
- ; Initial Loop
- :loop
- filereadln fhandle ip_address
- if result goto fine
- flushrecv
- ;°°°°°°°°°°°°°°°° CONNESSIONE °°°°°°°°°°°°°°°°°°°°°°°°°
- ; TT connects to one of the addresses in the list specified above
- connect ip_address
- ;°°°°°°°°°°°°°°°° INVIO USERNAME °°°°°°°°°°°°°°°°°°°°°°
- ; Routine for sending username to host
- wait 'Username:'
- if result=0 then
- space = '_'
- strconcat Ip_address space
- strconcat Ip_address 'non connessa'
- filewriteln fh ip_address
- goto prossimo
- endif
- sendln username
- ;°°°°°°°°°°°°°°°° INVIO PASSWORD °°°°°°°°°°°°°°°°°°°°°°
- ; Routine for sending password to host
- wait 'Password:'
- if result=0 then
- space = '_'
- strconcat Ip_address space
- strconcat Ip_address 'Tacacs non funzionante'
- filewriteln fh ip_address
- goto prossimo
- endif
- setsync 1
- sendln password
- setsync 0
- ;°°°°°°°°°°°°°°°° CONTROLLO LINEA BGP °°°°°°°°°°°°°°°°°°°°°°
- ; TT sends commands for checking BGP links
- ;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
- flushrecv ;ensure nothing is in the buffer
- sendln 'terminal length 0'
- sendln 'sh bgp a s'
- for i 1 16
- recvln ;skip past technobabble
- next
- recvln
- filewriteln fh inputstr ;now save two relevant lines in a file
- recvln
- filewriteln fh inputstr
- goto prox
- ;°°°°°°°°°°°°°°°° DISCONNESSIONE con HOST °°°°°°°°°°°°°°°°
- ; Disconnect from the host
- sendln 'exit'
- ;°°°°°°°°°°°°°°°° LOOP °°°°°°°°°°°°°°°°°°°°°°°°°°°°
- ;Loop Procedure
- :prox
- pause 1
- disconnect
- closett
- goto loop
- ;°°°°°°°°°°°°°°°°° FINE PROGRAMMA °°°°°°°°°°°°°°°°°°°°°°
- ; Close TT after ll IP have been processed
- :end
- fileclose fhandle
- end
I would put in a testlink after your connect to make sure the connect worked. I think you might be having another issue related to perhaps your hardware or network setup that is not allowing you to connect.
As a suggestion, do a minor rewrite to get rid of all GOTO statements. They were unavoidable in TeraTERM 2.3, but the latest version has more than enough types of flow control statements to avoid them completely. This will save you much grief in the long run, trust me. Also, it would be easier to read if you only indented loops and if statement bodys.
Think Herman Melville instead of David Gerrold. Rather pretentious literary reference from my younger days that has somehow stuck.
Three types of connections
There are 3 types of connection you can establish from TeraTerm macro:
- Telnet connection (port 23)
- SSH1 or SSH2 connection (port 22)
- Connection via COM port
Telnet connections
Quote:connect 'myserver:23 /nossh'
or
Quote:
connect 'myserver:23 /telnet'or
Quote:
connect 'myserver:23'
Using /nossh is strongly recommended. Without this parameter TeraTerm will start connecting with the same method (telnet or SSH) that was used during last time when teraterm.ini file was saved. In case it was SSH than macro will try to connect via SSH and will eventually fail.
SSH connections
Quote:
connect 'myserver /ssh'Quote:
This way will start SSH connection without defining whether SSH1 or SSH2 has to be used.
connect 'myserver /ssh /1'
or
Quote:
connect 'myserver /ssh /2'Quote:
Parameters /1 and /2 force to use SSH1 or SSH2 method.
connect 'myserver /ssh /auth=password /user=username /passwd=password'
or
Quote:
connect 'myserver /ssh /1 /auth=password /user=username /passwd=password'or
Quote:
connect 'myserver /ssh /2 /auth=password /user=username /passwd=password'
or
Quote:
connect 'myserver /ssh /auth=publickey /user=username /passwd=password /keyfile=private-key-file'or
Quote:
connect 'myserver /ssh /1 /auth=publickey /user=username /passwd=password /keyfile=private-key-file'
or
Quote:
connect 'myserver /ssh /2 /auth=publickey /user=username /passwd=password /keyfile=private-key-file'Quote:
Above 6 ways allow to skip popup dialog and pass username and password directly from macro. Please note that /auth=password or /auth=publickey is the parameter saying that authentication will be done by entering password or private-key-file thus you should not replace the word 'password' or the word 'publickey' in it with actual values. Only the words shown above with italic font have to be substituted.
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 @@.
Please remember that entering actual username and password in TeraTerm macro will cause them to be stored as an open text and it is your responsibility to keep such macros in secure place.
A little bit better practice is to use getpassword and passwordbox commands that store encrypted passwords in the file.
connect 'myserver /ssh /auth=password /user=username /ask4passwd'
or
Quote:
connect 'myserver /ssh /1 /auth=password /user=username /ask4passwd'or
Quote:
connect 'myserver /ssh /2 /auth=password /user=username /ask4passwd'
or
Quote:
connect 'myserver /ssh /auth=publickey /user=username /ask4passwd /keyfile=private-key-file'or
Quote:
connect 'myserver /ssh /1 /auth=publickey /user=username /ask4passwd /keyfile=private-key-file'
or
Quote:
connect 'myserver /ssh /2 /auth=publickey /user=username /ask4passwd /keyfile=private-key-file'Quote:
Above 6 ways pass username and authentication method directly from macro, and the popup asks for password.
Connections via COM port
connect '/C=x'
Here x represents COM port number. For example to connect via COM port 1 the command will look like: connect '/C=1'
About setsync
It is highly recommended to use the macro command
Quote:
setsync 1
right after the command connect. This command switches TeraTerm into synchronous communication mode in which the buffer never overflows. See TeraTerm Macro help for more details.
_________________
Thanks.
Best regards,
// Boris
linkstate
Joined: 16 Mar 2007
Posts: 7
Posted: Fri Mar 16, 2007 5:34 pm Post subject: First step to Tera Term Macros
![]()
First to all I want to congratulate this wonderful tool of trade
I'm willing to take my first step into Tera Term Macros and I will probably won't make it on my own.
So here's the deal.
I want to be able to telnet to an access router in a companies HQ and then telnet into all the switches and do a "show tech" command in order to backup all the configs and informations about the switches into a text file.
All the switches are Cisco 2950.
Please help this poor man in need of your assistance.
With My best regards, boris====
Newbie
Joined: 16 Mar 2007
Posts: 7
boris
Posted: Fri Mar 16, 2007 8:24 pm Post subject: ![]()
I'm feeling a bit fuzzy about this ....
My first piece of code turned out something like this:
connect 'ip address:23 /nossh' ----> that's my office
wait'Username:'
sendln'usernamexxx'
wait'Password:'
sendln'passwordxxx'
wait'hostname>'
sendln'telnet 172.23.128.11' ----> that's the HQ of the company
wait'Username:'
sendln'usernamexxx'
wait'Password:'
sendln'passwordxxx'
fileopen filehandle 'file.txt' 0
filereadln filehandle line
while result=0
sendln line
wait'Username:'
sendln'usernamexxx'
sendln'passwordxxx'
sendln 'show tech'
sendln'exit'
endwhile
exit
My problem is that the macro does read the first ip address of the text file but it doesn't continue with the other ones.
Regarding the issue of saving the logs with each hostname or ip address, that remains a complete phantom to me.
Hope that explained myself correctly to you.
My regards,
Guru
Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
linkstate
Posted: Sat Mar 17, 2007 6:22 am Post subject: ![]()
Do you have word 'telnet' followed by IP address on each line of your file.txt?
_________________
Thanks.
Best regards,
// Boris
Newbie
Joined: 16 Mar 2007
Posts: 7
boris
Posted: Sat Mar 17, 2007 2:45 pm Post subject: ![]()
No. Just the ip addresses. why ? is it supposed to ?
Guru
Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
Posted: Sat Mar 17, 2007 5:03 pm Post subject: ![]()
The same way as you do earlier in your script, you need to pass method of connection and IP address in
Quote: sendln'telnet 172.23.128.11' Content of variable line is one string of your file.txt. If file does not contain words 'telnet' than you get as the result
Quote: sendln line
which is the same as if you would type only IP address at command prompt without mentioning whether you need telnet, ssh, rlogin etc.
Code: sendln 172.23.x.y ; <- whatever IP you have
Instead of adding 600 words 'telnet' to your file, the better approach would be to concatenate word 'telnet' and IP taken from the file.
The code can look like this:
Code: ...
fileopen filehandle 'file.txt' 0
filereadln filehandle line
while result=0
connect_line='telnet ' ; <-- make sure you have trailing space
strconcat connect_line line
sendln connect_line
wait'Username:'
sendln'usernamexxx'
sendln'passwordxxx'
sendln 'show tech'
sendln'exit'
endwhile
...
_________________
Thanks.
Best regards,
// Borislinkstate
Newbie
Joined: 16 Mar 2007
Posts: 7
Posted: Sun Mar 18, 2007 10:46 am Post subject: ![]()
Okay.
I have something like this...
I'm testing with a .txt file with just two ip addresses for testing.
The thing is that he only telnets into the first ip address in that file and doesn't jump into the 2 ip address.
Could it be something with the while procedure ?
sendln line
while result=0
connect_line='telnet ' ;
strconcat connect_line line
wait'Username:'
sendln'XXXXX'
sendln'XXXX'
timeout = 4
sendln 'show tech'
sendln'exit'
endwhile
Thank you for your assistanceboris
Guru
Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
Posted: Sun Mar 18, 2007 11:11 am Post subject:
![]()
Read description of strconcat function. Your connection string is in connect_line and not in line.
There are few other issues with your last code. Please post here your complete macro, otherwise it is unclear if there are scripting or copy/pasting errors.
_________________
Thanks.
Best regards,
// Borislinkstate
Newbie
Joined: 16 Mar 2007
Posts: 7
Posted: Sun Mar 18, 2007 11:18 am Post subject:
![]()
Let me see if I can explain this better to you.
Here's the whole code with comments
connect '213.xx.xx.xx:23 /nossh' ---> My first telnet to my company
wait'Username:'
sendln'xxxxxxx'
wait'Password:'
sendln'xxxxxxx'
wait'hostname>'
sendln'telnet 172.23.xx.xx' ---------> My telnet to the other company
wait'Username:'
sendln'xxxxx'
wait'Password:'
sendln'xxxxxxx'
-------------"So far So good here"--------------------
fileopen filehandle 'andre.txt' 0
filereadln filehandle line
sendln line
while result=0
connect_line='telnet ' ;
strconcat connect_line line
wait'Username:'
sendln'xxxxx'
wait'Password:'
sendln'xxxxx'
timeout = 4
sendln 'xxxxx'
sendln'exit'
endwhile
exitboris
Guru
Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
Posted: Sun Mar 18, 2007 2:48 pm Post subject:
![]()
Try this code
Code: connect '213.xx.xx.xx:23 /nossh'
wait 'Username:'
sendln 'xxxxxxx'
wait 'Password:'
sendln 'xxxxxxx'
wait 'hostname>'
sendln 'telnet 172.23.xx.xx'
wait 'Username:'
sendln 'xxxxx'
wait 'Password:'
sendln 'xxxxxxx'
fileopen filehandle 'andre.txt' 0
while result=0
connect_line='telnet '
filereadln filehandle line
strconcat connect_line line
sendln connect_line
wait 'Username:'
sendln 'xxxxx'
wait 'Password:'
sendln 'xxxxx'
timeout = 4 ; I'm not sure why do you need this line
sendln 'xxxxx' ; and this line
sendln 'show tech'
wait 'xxxxxxxxx' ; <= whatever appears at the end of 'show tech' printout
sendln 'exit'
endwhile
fileclose filehandle
exit
_________________
Thanks.
Best regards,
// BorisIshmaelCallMe
Coach
Joined: 25 Jan 2006
Posts: 119
Location: Denver, Colorado, USA
boris
Posted: Mon Mar 19, 2007 6:53 am Post subject:
![]()
You need to move your filereadln command to just before the while and a copy of it to just before the endwhile so that the result variable gets set correctly for both the first and subsequent loops.
Guru
Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
Mon Mar 19, 2007 7:14 am Post subject: Thanks, I missed thatCode:
connect '213.xx.xx.xx:23 /nossh'
wait 'Username:'
sendln 'xxxxxxx'
wait 'Password:'
sendln 'xxxxxxx'
wait 'hostname>'
sendln 'telnet 172.23.xx.xx'
wait 'Username:'
sendln 'xxxxx'
wait 'Password:'
sendln 'xxxxxxx'
fileopen filehandle 'andre.txt' 0
filereadln filehandle line
while result=0
connect_line='telnet '
strconcat connect_line line
sendln connect_line
wait 'Username:'
sendln 'xxxxx'
wait 'Password:'
sendln 'xxxxx'
timeout = 4 ; I'm not sure why do you need this line
sendln 'xxxxx' ; and this line
sendln 'show tech'
wait 'xxxxxxxxx' ; <= whatever appears at the end of 'show tech' printout
sendln 'exit'
filereadln filehandle line
endwhile
fileclose filehandle
exit
_________________
Thanks.
Best regards,
// BorisIshmaelCallMe
Coach
Joined: 25 Jan 2006
Posts: 119
Location: Denver, Colorado, USA
Posted: Mon Mar 19, 2007 8:11 am
There ya go, that oughta work.
One additional thing I would suggest to the original poster is to set the "timeout" variable BEFORE anyents (not in the middle of the loop, as it is ) and then (ideally) check the "result" variable each time.
If the timeout variable is not set, I believe it defaults to 0, which means the script will wait forever at that point if the text does not show up.Recommended Links
Good source of inspiration can also be
- Teraterm Scripts - Texas Instruments Embedded Processors Wiki
- Tera Term Support forum by Boris Maisuradze
- Tera Term TTL Scripting example for CLI based devices
Forums
Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Disclaimer:
- The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with.
- We do not warrant the correctness of the information provided or its fitness for any purpose
- In no way this site is associated with or endorse cybersquatters using the term "softpanorama" with other main or country domains (e.g. softpanorama.com) with bad faith intent to profit from the goodwill belonging to someone else.
Last modified: August 12, 2009