Softpanorama
May the source be with you, but remember the KISS principle ;-)

Contents Bulletin Scripting in shell and Perl Network troubleshooting History Humor

TeraTerm Macros

News Teraterm Recommended Links Reference

Connect command

How to use Tera Term for the Serial Console
Expect SSH Password-less SSH login Telnet protocol Serial Console on Solaris sshfs
CygTerm+ LogMeTT Programmable Keyboards Tips Humor Etc

Introduction

Teraterm macro language is documented at MACRO Help Index.  They can be created in any text editor. There is VIM script that provide highlighting for Teraterm --  Teraterm MACRO syntax highlighting vim online. The extension used for Teraterm macros is .ttl.  you can launch the macro by just cling on the file is the right program is associated with this extension.

Note:

You need to associate extension ttl with ttpmacro.exe. In windows XP this is done automatically but in windows 7 you need to check if correct association is present. Sometimes Windows 7 this extension is associated with teraterm.exe you will get message invalid host for any macro. See Associate a File Type or Protocol with a Program in Windows 7 [How To]

To run macro from within TeraTerm you need to click on Macro  in Control tab and select the macro to run (can be automated via Programmable Keyboards such as Logitech G510s gaming keyboard):

TeraTerm Macro language for dummies

TTL is a simple interpreted language like BASIC. To learn TTL quickly, it is best to study the sample macro files in the distribution package and look at the command reference for constructs you do not understand. There are also several soures of good examples on the Web, see Teraterm Scripts - Texas Instruments Wiki

Here is a brief tutorial called TeraTerm Macro language for dummies

TeraTerm basics

So to start things off, let's deal with variables.

There are two types of variables: Strings (limited to 255 characters) , and Integers (Limited to ~ +/-2 billion) (want to go bigger?). The type is determined implicitly when the variable is created and cannot be altered afterwards.

Also, since TeraTerm 4.72, there are now arrays of both of these types (limited to 65536 indices per array)

  1. integerVariable=10 ; An Integer variable
  2. strVariable='asdf' ; A string variable
  3. strVariable2='0' ; Still a string variable
  4. integerVariable='asdf' ; ERROR!!!!!!
  5. integerVariable=2
  6. ; A little fun with arrays:
  7. intdim integerArray 10 ; Create an integer array of size 10
  8. integerArray[0]=10 ; Assigns the first element of the array to 0
  9. integerArray[10]=10 ; ERROR!!!!!
  10. ; It's almost exactly the same for strings, just using strdim instead:
  11. strdim strArray integerVariable ; Creates a string array that has the size given in integerVariable
  12. ; Also, by the way, the semicolon (;) is the character that denotes a comment; anything after it in a line has no effect on the running of your script (notice how I used the semicolon in a grammatically correct way in a sentence about semicolons ;-)
But variables by themselves are boring. The real basis of any programming language is the if statement. However an if statement by itself is somewhat boring, so let's go a little further and also show you a wait statement:
  1. wait 'value = 0' 'ERROR'
  2. if result=1 then
  3. ; value = 0 was received on the terminal
  4. elseif result=2
  5. ; ERROR was received on the terminal
  6. endif
The wait statement is one of the more or less unique features of TeraTerm. Essentially, it reads through all of the serial output that hasn't been parsed yet, and when one of the strings in its sensitivity list is found, it sets result to the index of that string and moves on. The documentation for the setsync command has a partial general overview for how TeraTerm internally works.

Note that you can also set a timeout for wait, and it will then only hold up the execution of the script for at most timeout.mtimeout seconds:

  1. timeout=1
  2. mtimeout=500 ; Set the timeout for 1.5 seconds
  3. wait 'Good' 'Bad'
  4. if result=0 then
  5. ; Neither good nor bad appeared in the terminal output during the 1.5 seconds
  6. endif
A nice counterpoint to the 'wait' command is the 'sendln' and 'send' commands. These guys do pretty much what their names suggest: they write stuff back out to the terminal (with sendln adding a newline at the end of its string).

A common use that I have for the wait/sendln pair is to send a series of commands to a machine.
For example, when sending a series of commands to a Linux box, it might look something like the following:

  1. wait 'root@localhost#'
  2. sendln 'command'
  3. wait 'root@localhost#'
  4. sendln 'command'
  5. wait 'root@localhost#'
  6. sendln 'command'
This ensures that the prior command has finished before you send the next command. The sendkcode command is also occasionally useful in some cases.

Note that the above code is somewhat ugly. If the prompt were to change (say from root@localhost to root@servername), I'd have to manually replace a bunch of lines. Since I'm lazy, the following format is much nicer:

  1. cmdPrompt='root@localhost'
  2. wait cmdPrompt
  3. sendln 'command'
  4. wait cmdPrompt
  5. sendln 'command'
  6. wait cmdPrompt
  7. sendln 'command'
That looks much nicer.

Looping

Branching is all well and good, but eventually you will want to do something that has some repetition in it. Teraterm has several more or less standard looping constructs

  1. do while i>0
  2.     i = i - 1
  3. loop
  4. do
  5.     i=i-1
  6. loop while i>0
  7. for j 1 10
  8.     i=j+i
  9. next
  10. until i > 10
  11.   i = i + 1
  12. enduntil
  13. while i>0
  14.   i = i - 1
  15. endwhile
I won't go into too much detail about all of these; TeraTerm probably has more looping constructs than is really healthy, but definitely keep in mind the 'for' loop, and the fact that the 'do while' loop can be done as a pre-test loop or a post-test loop. The 'break' command can also be used to escape from a loop before its condition triggers

Lastly for the basics is TeraTerm's goto command. Some people (especially those experienced with C and who have experienced the nightmares of spaghetti code) view gotos as positively evil and wish they could be nuked from every language in existence. Gotos can do just about anything, but typically not as nicely as one of the above looping structures. About the only place that gotos should really go is in error handling:

  1. wait 'Good' 'Bad'
  2. if result=2 goto ERROR
  3. ; Presumably, a bunch of non-related code goes here
  4. exit ; Typically, you don't want to execute the error code upon successful completion of the normal code, so this exits before doing that
  5. :ERROR
  6. ; Error-handling/messaging code goes here
  7. exit
TeraTerm and regular expressions

Regular expressions are an interesting creature in and of themselves. An old and relatively well-known quote about regular expressions (regexes) goes something like this:

Quote: Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.

Regexes are a double-edged sword that allow you to do stuff with strings that would normally not be possible. Since I don't really want to go into all the nitty gritty, here's a link to wikipedia, as well as afairly-well-laid-out regex tutorial site. Note that TeraTerm has also posted a reference for the regex engine that they use, but that isn't really laid out for learning...

TeraTerm has several commands which use the power of regular expressions (let me know which one's I'm forgetting...):

  1. waitregex <string1 with regular expression> [<string2 with regular expression> ...]
  2. strmatch <target string> <string with regular expression>
  3. strreplace <strvar> <index> <regex> <newstr>
strmatch and strreplace are both relatively normal. You put your regular expression in, and TeraTerm works its magic.

waitregex is a beast that I've seen misused in these forums time and again. In many ways, it is identical to the wait command, just with regular expression support. The large difference is with regular expression matching. Regular expression matching is what happens when a regular expression with parenthesis triggers on a string. The result inside the string is then returned (in normal regular expressions, it is returned as \1, \2, \3, etc, while with TeraTerm, they are stored in the groupmatchstr1, groupmatchstr2,...,groupmatchstr9 variables).

An example is as follows:

  1. waitregex 'value = ([0-9]+)' 'ERROR'
  2. if result=1 then
  3.     str2int returnValue groupmatchstr1
  4. endif
Let's pick the above code fragment apart bit by bit. First we have '[0-9]+' This regex essentially grabs the largest amount of consecutive characters that fall between 0 and 9. The parenthesis '(...)' are what initiate the grouping. With the parenthesis, the string that was caught by '[0-9]+' gets stored into groupmatchstr1. If the regular expression as a whole was triggered, the result will be one and the if statement will let the str2int command work its magic. The str2int command (and its counterpart, the int2str command) do exactly what their names suggest: convert between string and integer variables.

Thus, if the 'value = 5643' was received on the terminal, this code would set returnValue to 5643

Note that waitregex only works on the first 255 characters of a line, so anything further than that and you're going to have to find another way.

File input and output

My file I/O skills are minimal at best. Anything that you'd care to offer is gladly accepted
Also, don't forget about the ability to use logging commands in some cases (check out loginfo, logopen, logclose, logstart, logpause, and logwrite)

User input and output

Most of the commands used here are described in the Miscellaneous Commands section of the TTL Command Reference.

  1. messagebox <message> <title>
This is one of the most commonly-used UI-type commands of the macro language. It pops up a window with the title equal to <title>, and the content equal to <message>, with an Ok button at the bottom. Note that code beneath this command won't execute until Ok is clicked.
  1. yesnobox <message> <title>
This is almost identical to the messagebox, however rather than an Ok button, there's a Yes and a No button. If Yes is clicked, result=1, otherwise result=0
  1. inputbox <message> <title> [<default>]
The third of the *box commands that I use on a normal basis, this is like the messagebox command, but with an area that the user can type stuff in. That area is populated with <default> when the window first appears, and after the user clicks Ok, the variable 'inputstr' contains the value of that area.

System variables reference

The table below is from Teraterm manual

There are two types of variables in Terterm macro language:

*1 The second to ninth command line parameter of MACRO. The first parameter (param1) is the macro file name. "paramcnt" is a number of parameter counter including the fisrt parameter. 
*2 Precision is about 50 msec.

Usage of connect command and sample macros

The central command is Connect command for which we have a special page. Teraterm distribution contains six sample macros that illustrate is use. Examples are outdated and too chatty, but still useful:

delpassw.ttl
dialup.ttl
index
login.ttl
mpause.ttl
random.ttl
screencapture.ttl
ssh2login.ttl
wait_regex.ttl

The most important are two macros: login.ttl and ssh2login.ttl. They are a little bit too general to my taste and can benefit from some minor tweaking before you adopt them for login to real servers.  For example ssh2login.ttl asks a lot of unnecessary questions ;-)

... ... ... 

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

connect msg
For Solaris servers it can be modified to
msg = 'box106.myfirma.com:22 /ssh /auth=password /user=root /passwd=mypass-1234'
connect msg
wait   "#"
sendln "bash"
sendln ". ~likbez/.profile"
sendln "cd ~likbez" 

For Linux boxes bash shell is default for root so the line sendln "bash" is redundant. After such a tweaking and testing, you can rename is to box106.ttl, drag this macro to the desktop and repeat the process for other servers so that each macro is individual to a server and represented by an icon.  Clicking on this icon will launch the macro that login you to a server. Say unto a hundred servers (ten rows ten servers each) this approach works reasonably well, especially if you have dual display configuration (in this case you better put icons on the second display). If you have more then that use folders for groups of similar servers such as Solaris, HP-UX, Linux, AIX and  put of the desktop folders instead of icons for the macros. Clicking on this icon will launch the macro. This way you can have unique macros for each of your important servers so that you do not need to recreate environment and other preliminary steps manually for it.  That can save a lot of time and is simpler and more efficient then programming keyboard macros.

You just need to write a script in Cygwin that changes passwords when time has come from a special table, using secret formula (for example $pass=$this_month_prefix."-".substr($server_name,-4) ), or whatever.

You can also use Passwordless SSH login for authentication to you own account and use sudo to get to root. That removes the choir of changing root accounts periodically.

Good source of inspiration for creating more complex Teraterm macros can be

For you convenience (and as the mean to archive important page in case it disappears from the web)   examples are reproduced below:

__common.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __common.ttl
;;
;;  desc    Common definitions used across the macros.
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  Current Date
;;
getdate CurDate
 
 
;;
;;  Current Time
;;
gettime CurTime
 
 
;;
;;  Title of the Tera Term Window
;;
StrWindowTitle     = 'OMAP35x EVM'
 
 
;;
;;  Boot methods
;;
Boot_RAMDISK    = 'RAMDISK'
Boot_NFS        = 'NFS'
 
 
;;
;;  Is Lauterbach used for debug?
;;
UseLauterbach   = 0
 
 
;;
;;  Caption prefix
;;
StrCaption    = ':::::::::::::::::::::::::::::::::::::::: '
 
 
;;
;;  Dividers
;;
StrEmpty        = ''#13#10
StrDivider_1    = '====================================================='#13#10
StrDivider_2    = '-----------------------------------------------------'#13#10
StrDivider_3    = '.....................................................'#13#10
 
 
;;
;;  Set position of status dialog box
;;
setdlgpos 10 10
 
 
;;
;;  Set window title
;;
settitle StrWindowTitle

__uboot-config-common.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __uboot-config-common.ttl
;;
;;  desc    Common u-boot related definitions
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  The u-boot message to stop autoboot.
;;
 
MsgAutoboot     = 'Hit any key to stop autoboot:'
 
;;
;;  The u-boot prompt
;;
PromptUboot     = 'OMAP3EVM #'
 
 
;;  ============================================================================
;;  EXECUTION
;;  ============================================================================
 
;;
;;  Disable autoload
;;
wait PromptUboot
sendln 'setenv autoload no'

__uboot-config-network.ttl

This file uses dummy values for various macros. They need to be defined with correct values for your platform.

;;  Tera Term Macro
;;  ============================================================================
;;  file    __uboot-config-network.ttl
;;
;;  desc    Configure the u-boot network settings.
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  Ethernet on EVM
;;
VarMacAddr      = 'A1:B1:C1:E1:D1:E1'
VarGatewayIP    = '192.168.1.1'
VarNetMask      = '255.255.255.0'
 
;;
;;  Server running the TFT Server
;;
VarServerIP     = '192.168.1.2'
 
;;
;;  Get IP address from DHCP server
;;
CmdDHCP             = 'dhcp'
 
 
;;  ============================================================================
;;  EXECUTION
;;  ============================================================================
 
;;
;;  Setup Network
;;
wait PromptUboot
sendln 'setenv ethaddr ' VarMacAddr
 
wait PromptUboot
sendln 'setenv gatewayip ' VarGatewayIP
 
wait PromptUboot
sendln 'setenv netmask ' VarNetMask
 
;;
;;  Set the IP address of the TFTP Server
;;
wait PromptUboot
sendln 'setenv serverip ' VarServerIP
 
;;
;;  Get an IP Address
;;
wait PromptUboot
sendln CmdDHCP
 
;;
;;  Set the IP address of the TFTP Server again.
;;  (Required on some networks)
;;
wait PromptUboot
sendln 'setenv serverip ' VarServerIP

__uboot-load-kernel.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __uboot-load-kernel.ttl
;;
;;  desc    Steps to boot the Linux kernel.
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  Name of the boot file
;;
BootFile            = 'uImage'
 
;;
;;  Boot arguments
;;
BootArgs_RAMDISK    = 'console=ttyS0,115200n8 mem=128M root=/dev/ram0 rw initrd=0x81600000,16M ip=dhcp'
BootArgs_NFS        = 'console=ttyS0,115200n8 mem=128M root=/dev/nfs noinitrd nfsroot=192.168.1.10:/home/user/remote/098,nolock,rsize=1024,wsize=1024 ip=dhcp'
 
;;
;;  Boot commands
;;
CmdLoadRamDisk      = 'tftpboot 0x81600000 kernel/ramdisk.gz'
CmdLoadUimage       = 'tftpboot 0x80000000 kernel/uImage'
CmdBootm            = 'bootm 0x80000000'
 
;;  ============================================================================
;;  EXECUTION
;;  ============================================================================
 
;;
;;  General configuration
;;
wait PromptUboot
sendln 'setenv bootfile ' BootFile
 
;;
;;  Set boot arguments
;;
wait PromptUboot
 
strcompare VarBootMethod Boot_RAMDISK
if result=0 then
    sendln 'setenv bootargs ' BootArgs_RAMDISK
endif
 
strcompare VarBootMethod Boot_NFS
if result=0 then
    sendln 'setenv bootargs ' BootArgs_NFS
endif
 
;;
;;  Print current environment (Just for the record)
;;
wait PromptUboot
sendln 'printenv'
 
;;
;;  Load RamDisk Image
;;
strcompare VarBootMethod Boot_RAMDISK
if result=0 then
    wait PromptUboot
    sendln CmdLoadRamDisk
endif
 
;;
;;  Load uImage
;;
wait PromptUboot
sendln CmdLoadUimage
 
;;
;;  Boot Linux
;;
wait PromptUboot
if UseLauterbach=0 then
    sendln CmdBootm
elseif UseLauterbach=1 then
    send CmdBootm
endif

__kernel-common.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __kernel-common.ttl
;;
;;  desc    Common kernel related definitions & commands.
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  The Linux kernel prompt
;;
PromptLinux     = '[root@OMAP3EVM /]# '
 
;;
;;  Clear screen
;;
CmdClear        = 'clear'

__kernel-power.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __kernel-power.ttl
;;
;;  desc    Common power related definitions and commands.
;;  ============================================================================
;;  HISTORY
;;
;;      2008-04-25                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  Set LCD timeout to 2 secs
;;
CmdFbTimeout	= 'echo 2 > /sys/power/fb_timeout_value'
 
;;
;;  Different pause durations used in testing
;;
PauseLog            = 2
PauseNormal         = 30
PauseSuspendBefore  = 5
PauseSuspendAfter   = 10
 
;;
;;  Strings indicating sleep duration
;;
StrSleepNormal          = 'Wait for 30 secs'#13#10
StrSleepBeforeSuspend   = 'Wait for 5 secs'#13#10
StrSleepAfterSuspend    = 'Wait for 60 secs'#13#10
 
;;
;;  Strings indicating actions performed
;;
StrSuspend              = 'Attempt Suspend'#13#10
StrResume               = 'Attempt Resume (send key click)'#13#10
 
StrViewPowerStates      = 'View previous power states'#13#10
StrViewDeepestIdleState = 'View the deepest IDLE state'#13#10
 
StrViewGovernor         = 'View current governor'#13#10
 
StrViewVDD1             = 'View VDD1 OPP'#13#10
StrViewVDD2             = 'View VDD2 OPP'#13#10
 
StrViewClock_MPU_IVA    = 'View MPU & IVA clocks'#13#10
StrViewClock_VirtVDD    = 'View virtual VDD clocks'#13#10
 
;;  ----------------------------------------------------------------------------
;;  CPUIDLE
;;  ----------------------------------------------------------------------------
 
;;
;;  Set deepest IDLE state
;;
CmdShowPowerStates	= 'cat /proc/pm_prepwst'
 
;;
;;  Show current deepest IDLE state
;;
CmdShowDeepestIdleState	= 'cat /sys/power/cpuidle_deepest_state'
 
;;
;;  Show status of OMAP clocks
;;
CmdShowClocks	= 'cat /proc/omap_clocks'
 
;;
;;  Set deepest IDLE state
;;
CmdSetDeepestIdleState_0  = 'echo "0" > /sys/power/cpuidle_deepest_state'
CmdSetDeepestIdleState_1  = 'echo "1" > /sys/power/cpuidle_deepest_state'
CmdSetDeepestIdleState_2  = 'echo "2" > /sys/power/cpuidle_deepest_state'
CmdSetDeepestIdleState_3  = 'echo "3" > /sys/power/cpuidle_deepest_state'
CmdSetDeepestIdleState_4  = 'echo "4" > /sys/power/cpuidle_deepest_state'
CmdSetDeepestIdleState_5  = 'echo "5" > /sys/power/cpuidle_deepest_state'
CmdSetDeepestIdleState_6  = 'echo "6" > /sys/power/cpuidle_deepest_state'
 
;;
;;  Put system to 'suspend' state
;;
CmdSuspend	= 'echo -n "mem" > /sys/power/state'
 
 
;;  ----------------------------------------------------------------------------
;;  CPUFREQ
;;  ----------------------------------------------------------------------------
 
;;
;;  OMAP Clocks
;;
CmdShowAllClocks  = 'cat /proc/omap_clocks'
CmdShowClock_MPU  = 'cat /proc/omap_clocks | grep mpu'
CmdShowClock_IVA  = 'cat /proc/omap_clocks | grep iva'
CmdShowClock_VDDs = 'cat /proc/omap_clocks | grep virt'
 
 
;;
;;  Governor related
;;
CmdShowGovernor            = 'cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
 
CmdSetGovernor_Ondemand	   = 'echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
CmdSetGovernor_Performance = 'echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
 
;;
;;  Set OPPs for VDD1
;;
CmdSetVDD1_1  = 'echo "1" > /sys/power/vdd1_opp_value'
CmdSetVDD1_2  = 'echo "2" > /sys/power/vdd1_opp_value'
CmdSetVDD1_3  = 'echo "3" > /sys/power/vdd1_opp_value'
CmdSetVDD1_4  = 'echo "4" > /sys/power/vdd1_opp_value'
CmdSetVDD1_5  = 'echo "5" > /sys/power/vdd1_opp_value'
 
CmdShowVdd1     = 'cat /sys/power/vdd1_opp_value'
 
;;
;;  Set OPPs for VDD2
;;
CmdSetVDD2_1  = 'echo "1" > /sys/power/vdd2_opp_value'
CmdSetVDD2_2  = 'echo "2" > /sys/power/vdd2_opp_value'
 
CmdShowVdd2     = 'cat /sys/power/vdd2_opp_value'

__test-cpuidle.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __test-cpuidle.ttl
;;
;;  desc    Unit tests for "cpuidle" framework.
;;  ============================================================================
;;  HISTORY
;;
;;      2008-04-25                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
include '__common.ttl'
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  Testcase title
;;
StrDescription     = 'UNIT TEST CASES FOR CPUIDLE'#13#10
 
 
;;
;;  Strings indicating deepest idle state
;;
StrDeepestIdleState_0   = 'Deepest Idle State = 0'#13#10
StrDeepestIdleState_1   = 'Deepest Idle State = 1'#13#10
StrDeepestIdleState_2   = 'Deepest Idle State = 2'#13#10
StrDeepestIdleState_3   = 'Deepest Idle State = 3'#13#10
StrDeepestIdleState_4   = 'Deepest Idle State = 4'#13#10
StrDeepestIdleState_5   = 'Deepest Idle State = 5'#13#10
StrDeepestIdleState_6   = 'Deepest Idle State = 6'#13#10
StrDeepestIdleState_9   = 'Deepest Idle State = 9 (
ss="co1">;; ============================================================================ ;; EXECUTION ;; ============================================================================   wait PromptLinux   sendln CmdFbTimeout wait PromptLinux   sendln wait PromptLinux   ;; ;; Open log file ;; logopen 'test-cpuidle.log' 0 0 logstart   logwrite StrEmpty   logwrite StrCaption logwrite CurDate logwrite StrEmpty   logwrite StrCaption logwrite CurTime logwrite StrEmpty   pause PauseLog sendln wait PromptLinux   ; C0   StrStateCaption = StrDeepestIdleState_0 CmdDeepestIdleState = CmdSetDeepestIdleState_0   call ExecIdleTest   ; C1   StrStateCaption = StrDeepestIdleState_1 CmdDeepestIdleState = CmdSetDeepestIdleState_1   call ExecIdleTest   ; C2   StrStateCaption = StrDeepestIdleState_2 CmdDeepestIdleState = CmdSetDeepestIdleState_2   call ExecIdleTest   ; C3   StrStateCaption = StrDeepestIdleState_3 CmdDeepestIdleState = CmdSetDeepestIdleState_3   call ExecIdleTest   ; C4   StrStateCaption = StrDeepestIdleState_4 CmdDeepestIdleState = CmdSetDeepestIdleState_4   call ExecIdleTest   ; C5   StrStateCaption = StrDeepestIdleState_5 CmdDeepestIdleState = CmdSetDeepestIdleState_5   call ExecIdleTest   ; C6   StrStateCaption = StrDeepestIdleState_6 CmdDeepestIdleState = CmdSetDeepestIdleState_6   call ExecIdleTest   ; C9   StrStateCaption = StrDeepestIdleState_9 CmdDeepestIdleState = CmdSetDeepestIdleState_9   call ExecIdleTest_N   ; Return to C2   sendln sendln wait PromptLinux   sendln sendln CmdSetDeepestIdleState_2 wait PromptLinux   ; ---------------------------------------------------------------------------- ; Close log file ; ---------------------------------------------------------------------------- sendln wait PromptLinux   pause PauseNormal logclose   exit     ; ============================================================================ ; SUBROUTINES ; ============================================================================   :ExecIdleTest ; ============================================================================ ; Execute the CPUIDLE Tests ; ============================================================================ msgStatus = ''   ; State caption   strconcat msgstatus StrStateCaption statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrDivider_2 logwrite StrStateCaption logwrite StrDivider_2   pause PauseLog   ; Set deepest idle state ; (Additional 'newlines' sent just in case first is missed in deeper C states) sendln sendln wait PromptLinux sendln sendln CmdDeepestIdleState wait PromptLinux   pause PauseLog   ; View previous power states   logwrite StrEmpty logwrite StrCaption logwrite StrViewPowerStates logwrite StrEmpty   pause PauseLog   strconcat msgstatus StrViewPowerStates statusbox msgstatus TitleWindow   sendln sendln wait PromptLinux sendln sendln CmdShowPowerStates wait PromptLinux   pause PauseLog   ; Wait for 'PauseNormal' ; (Additional 'newline' sent just in case first is missed in deeper C states)   strconcat msgstatus StrSleepNormal statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrCaption logwrite StrSleepNormal logwrite StrEmpty   pause PauseNormal   sendln sendln wait PromptLinux   pause PauseLog   ; View previous power states (again) ; (Additional 'newline' sent just in case first is missed in deeper C states)   strconcat msgstatus StrViewPowerStates statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrCaption logwrite StrViewPowerStates logwrite StrEmpty   pause PauseLog   sendln sendln wait PromptLinux sendln sendln CmdShowPowerStates wait PromptLinux   pause PauseLog   ; Wait for 'PauseSuspendBefore' ; (Additional 'newline' sent just in case first is missed in deeper C states)   strconcat msgstatus StrSleepBeforeSuspend statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrCaption logwrite StrSleepBeforeSuspend logwrite StrEmpty   pause PauseSuspendBefore   sendln sendln wait PromptLinux   pause PauseLog   ; Suspend   strconcat msgstatus StrSuspend statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrCaption logwrite StrSuspend logwrite StrEmpty   pause PauseLog   sendln sendln wait PromptLinux sendln sendln CmdSuspend   ; Wait for 'PauseSuspendAfter'   strconcat msgstatus StrSleepAfterSuspend statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrCaption logwrite StrSleepAfterSuspend logwrite StrEmpty   pause PauseSuspendAfter   ; Resume   strconcat msgstatus StrResume statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrCaption logwrite StrResume logwrite StrEmpty   sendln wait PromptLinux   flushrecv   pause PauseLog   closesbox   return     ; ============================================================================ ; SUBROUTINE ; ; Execute the CPUIDLE Tests (Negative) ; ============================================================================ :ExecIdleTest_N   msgStatus = ''   ; State caption   strconcat msgstatus StrStateCaption statusbox msgstatus TitleWindow   logwrite StrEmpty logwrite StrDivider_2 logwrite StrStateCaption logwrite StrDivider_2   pause PauseLog   ; Set deepest idle state ; (Additional 'newline' sent just in case first is missed in deeper C states)   sendln sendln wait PromptLinux sendln sendln CmdDeepestIdleState wait PromptLinux   flushrecv   pause PauseLog   closesbox   return


	

__test-cpufreq.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    __test-cpufreq.ttl
;;
;;  desc    Unit tests for "cpufreq" framework.
;;  ============================================================================
;;  HISTORY
;;
;;      2008-04-25                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
include '__common.ttl'
 
;;  ============================================================================
;;  DEFINITIONS
;;  ============================================================================
 
;;
;;  Testcase title
;;
StrDescription     = 'UNIT TEST CASES FOR CPUFREQ'#13#10
 
;;
;;  Strings related to governors
;;
StrGovernorOndemand     = 'Set ONDEMAND Governor'#13#10
StrGovernorPerformance  = 'Set PERFORMANCE Governor'#13#10
 
;;
;;  Strings indicating OPPs
;;
StrOppVdd1_1   = 'VDD1 OPP = 1'#13#10
StrOppVdd1_2   = 'VDD1 OPP = 2'#13#10
StrOppVdd1_3   = 'VDD1 OPP = 3'#13#10
StrOppVdd1_4   = 'VDD1 OPP = 4'#13#10
StrOppVdd1_5   = 'VDD1 OPP = 5'#13#10
 
StrOppVdd1_6   = 'VDD1 OPP = 6 (Incorrect)'#13#10
 
StrOppVdd2_1   = 'VDD2 OPP = 1'#13#10
StrOppVdd2_2   = 'VDD2 OPP = 2'#13#10
StrOppVdd2_3   = 'VDD2 OPP = 3'#13#10
 
StrOppVdd2_4   = 'VDD2 OPP = 4 (Incorrect)'#13#10
 
;;
;;  Commands for negative testing
;;
CmdSetVDD1_6  = 'echo "6" > /sys/power/vdd1_opp_value'
CmdSetVDD2_4  = 'echo "4" > /sys/power/vdd2_opp_value'
 
 
;;  ============================================================================
;;  EXECUTION
;;  ============================================================================
wait PromptLinux
 
sendln CmdFbTimeout
wait PromptLinux
 
sendln CmdClear
wait PromptLinux
 
sendln
wait PromptLinux
 
;;
;;  Open log file
;;
logopen 'test-cpufreq.log' 0 0
logstart
 
logwrite StrEmpty
 
logwrite StrCaption
logwrite CurDate
logwrite StrEmpty
 
logwrite StrCaption
logwrite CurTime
logwrite StrEmpty
 
pause PauseLog
sendln
 
;   Show current governor & switch to 'ondemand' governor
 
StrStateCaption     = StrOppVdd1_1
CmdSetVDD1          = CmdSetVDD1_1
 
call ExecGovernors
 
;   VDD1 - OPP1
 
StrStateCaption     = StrOppVdd1_1
CmdSetVDD1          = CmdSetVDD1_1
 
call ExecFreqTest
 
;   VDD1 - OPP2
 
StrStateCaption     = StrOppVdd1_2
CmdSetVDD1          = CmdSetVDD1_2
 
call ExecFreqTest
 
;   VDD1 - OPP3
 
StrStateCaption     = StrOppVdd1_3
CmdSetVDD1          = CmdSetVDD1_3
 
call ExecFreqTest
 
;   VDD1 - OPP5
;   (Do this early so we don't keep MPU in overdrive for long during negative
;    tests).
 
StrStateCaption     = StrOppVdd1_5
CmdSetVDD1          = CmdSetVDD1_5
 
call ExecFreqTest
 
;   VDD1 - OPP4
 
StrStateCaption     = StrOppVdd1_4
CmdSetVDD1          = CmdSetVDD1_4
 
call ExecFreqTest
 
;   VDD1 - OPP6 (Negative)
 
StrStateCaption     = StrOppVdd1_6
CmdSetVDD1          = CmdSetVDD1_6
 
call ExecFreqTest_N
 
;   VDD2 - OPP1
 
StrStateCaption     = StrOppVdd2_1
CmdSetVDD2          = CmdSetVDD2_1
 
call ExecFreqTest2
 
;   VDD1 - OPP2
 
StrStateCaption     = StrOppVdd2_2
CmdSetVDD2          = CmdSetVDD2_2
 
call ExecFreqTest2
 
;   VDD1 - OPP3
 
StrStateCaption     = StrOppVdd2_3
CmdSetVDD2          = CmdSetVDD2_3
 
call ExecFreqTest2
 
 
;   ----------------------------------------------------------------------------
;   Close log file
;   ----------------------------------------------------------------------------
sendln
wait PromptLinux
 
pause PauseNormal
logclose
 
exit
 
 
;   ============================================================================
;   SUBROUTINES
;   ============================================================================
 
:ExecGovernors
;   ============================================================================
;   Execute the CPUFREQ Tests
;   ============================================================================
msgStatus   = ''
 
;   State caption
 
strconcat msgstatus StrStateCaption
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrDivider_2
logwrite StrStateCaption
logwrite StrDivider_2
 
pause PauseLog
sendln
wait PromptLinux
 
;   Show current governor
strconcat msgstatus StrViewGovernor
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewGovernor
logwrite StrEmpty
 
sendln CmdShowGovernor
wait PromptLinux
 
pause PauseLog
 
;   Set 'ondemand' governor
 
strconcat msgstatus StrGovernorOndemand
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrGovernorOndemand
logwrite StrEmpty
 
pause PauseLog
 
sendln CmdSetGovernor_Ondemand
wait PromptLinux
 
;   View virtual VDD clocks
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewClock_VirtVDD
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowClock_VDDs
 
pause PauseLog
 
;   View current MPU & IVA clocks
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewClock_MPU_IVA
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowClock_MPU
 
pause PauseLog
 
sendln
wait PromptLinux
 
sendln CmdShowClock_IVA
wait PromptLinux
 
pause PauseLog
 
closesbox
 
return
 
 
:ExecFreqTest
;   ============================================================================
;   Execute the CPUFREQ Tests
;   ============================================================================
msgStatus   = ''
 
;   State caption
 
strconcat msgstatus StrStateCaption
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrDivider_2
logwrite StrStateCaption
logwrite StrDivider_2
 
pause PauseLog
 
;   Set VDD1 OPP
 
sendln
wait PromptLinux
 
sendln CmdSetVDD1
wait PromptLinux
 
pause PauseLog
 
;   View current VDD1 OPP
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewVDD1
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowVdd1
 
pause PauseLog
 
;   View current VDD2 OPP
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewVDD2
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowVdd2
 
pause PauseLog
 
;   View virtual VDD clocks
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewClock_VirtVDD
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowClock_VDDs
 
pause PauseLog
 
;   View current MPU & IVA clocks
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewClock_MPU_IVA
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowClock_MPU
 
pause PauseLog
 
sendln
wait PromptLinux
 
sendln CmdShowClock_IVA
wait PromptLinux
 
pause PauseLog
 
;   Wait for 'PauseSuspendBefore'
 
strconcat msgstatus StrSleepBeforeSuspend
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrSleepBeforeSuspend
logwrite StrEmpty
 
pause PauseSuspendBefore
 
sendln
wait PromptLinux
 
pause PauseLog
 
;   Suspend
 
strconcat msgstatus StrSuspend
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrSuspend
logwrite StrEmpty
 
pause PauseLog
 
sendln
sendln CmdSuspend
 
;   Wait for 'PauseSuspendAfter'
 
strconcat msgstatus StrSleepAfterSuspend
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrSleepAfterSuspend
logwrite StrEmpty
 
pause PauseSuspendAfter
 
;   Resume
 
strconcat msgstatus StrResume
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrResume
logwrite StrEmpty
 
sendln
wait PromptLinux
 
flushrecv
 
pause PauseLog
 
closesbox
 
return
 
 
:ExecFreqTest2
;   ============================================================================
;   Execute the CPUFREQ Tests (VDD2)
;   ============================================================================
msgStatus   = ''
 
;   State caption
 
strconcat msgstatus StrStateCaption
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrDivider_2
logwrite StrStateCaption
logwrite StrDivider_2
 
pause PauseLog
 
;   Set VDD2 OPP
 
sendln
wait PromptLinux
 
sendln CmdSetVDD2
wait PromptLinux
 
pause PauseLog
 
;   View current VDD1 OPP
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewVDD1
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowVdd1
 
pause PauseLog
 
;   View current VDD2 OPP
 
logwrite StrEmpty
logwrite StrCaption
logwrite StrViewVDD2
logwrite StrEmpty
 
pause PauseLog
 
sendln
wait PromptLinux
 
wait PromptLinux
sendln CmdShowVdd2
 
pause PauseLog
 
sendln
wait PromptLinux
 
flushrecv
 
pause PauseLog
 
closesbox
 
return
 
 
;   ============================================================================
;   SUBROUTINE
;
;   Execute the CPUFREQ Tests (Negative)
;   ============================================================================
:ExecFreqTest_N
 
msgStatus   = ''
 
;   State caption
 
strconcat msgstatus StrStateCaption
statusbox msgstatus TitleWindow
 
logwrite StrEmpty
logwrite StrDivider_2
logwrite StrStateCaption
logwrite StrDivider_2
 
pause PauseLog
 
;   Set VDD1 OPP
 
sendln
wait PromptLinux
 
sendln CmdSetVDD1
wait PromptLinux
 
flushrecv
 
pause PauseLog
 
closesbox
 
return

omap3evm-flash-uboot.ttl

 

omap3evm-boot-ramdisk.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    omap3evm-boot-ramdisk.ttl
;;
;;  desc    Steps to boot the Linux kernel using ramdisk on the OMAP3EVM.
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
include '__common.ttl'
 
VarBootMethod = Boot_RAMDISK
 
include '__uboot-config-common.ttl'
include '__uboot-config-network.ttl'
include '__uboot-load-kernel.ttl'
 
include '__kernel-common.ttl'
include '__kernel-boot.ttl'

omap3evm-boot-nfs.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    omap3evm-boot-nfs.ttl
;;
;;  desc    Steps to boot the Linux kernel using NFS on the OMAP3EVM.
;;  ============================================================================
;;  HISTORY
;;
;;      2007-11-30                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
include '__common.ttl'
 
VarBootMethod = Boot_NFS
 
include '__uboot-config-common.ttl'
include '__uboot-config-network.ttl'
include '__uboot-load-kernel.ttl'
 
include '__kernel-common.ttl'
include '__kernel-boot.ttl'

omap3evm-test-power.ttl

;;  Tera Term Macro
;;  ============================================================================
;;  file    omap3evm-test-power.ttl
;;
;;  desc    Steps to execute Power Management test cases on the OMAP3EVM.
;;  ============================================================================
;;  HISTORY
;;
;;      2008-04-25                      Sanjeev Premi
;;          Original Version
;;  ============================================================================
 
 
include '__common.ttl'
 
include '__kernel-common.ttl'
 
include '__kernel-power.ttl'
 
include '__test-cpuidle.ttl'
include '__test-cpufreq.ttl'
 
beep
pause 1
beep
pause 1
beep
What about DaVinci TeraTerm Scripts?

Below are a few simple scripts used to boot a DaVinci EVM - obviously you'll need to modify your IP address, kernel name and rootpath appropriately. These examples should serve as a good starting point if you want to create your own scripts.

To run the scripts, simply hit any key during the U-boot countdown to get to the U-boot prompt. Then run "Macro->Control" and browse to the *.ttl.

DM6446: Crossover Script

When you don't have a switch/router and need to boot your EVM using TFTP/NFS, you can directly connect your EVM to your laptop with a crossover cable. Here, the Linux host's IP address is set to 192.168.1.100 (modify as needed). To manually set the Linux host's IP address:

  1. host$ su - Login as root
  2. host# setup - Setup your network
  3. Browse to Network Configuration, then choose "Yes" (to Setup Network)
  4. Uncheck "Use dynamic IP configuration" using the spacebar (if needed)
  5. Tab to "IP address:" and type 192.168.1.100 and tab (using default values for Netmask, Gateway and Nameserver) to "OK" and hit Enter. Save your settings when prompted.
  6. host# /etc/init.d/network restart - Restart your network
  7. host# ipconfig - Verify that your IP address has been set to 192.168.1.100

Also, note the $(videoargs) setting below (setup for DVSDK 1.30)--if you are using an older DVSDK, simply remove $(videoargs) from the bootargs.

;; Tera Term Macro
;; ============================================================================
;; file dm6446_crossover.ttl
;; comments rename serverip, rootpath and bootfile
;; ============================================================================
 
showtt 0
setsync 1
 
sendln 'setenv serverip 192.168.1.100'
waitrecv '#' 1 0
 
sendln 'setenv ipaddr 192.168.1.101'
waitrecv '#' 1 0
 
sendln 'setenv nfshost $(serverip)'
waitrecv '#' 1 0
 
sendln 'setenv rootpath /home/user/target'
waitrecv '#' 1 0
 
sendln 'setenv videoargs video=davincifb:vid0=720x576x16,2500K:vid1=720x576x16,2500K:osd0=720x576x16,2025K davinci_enc_mngr.ch0_output=COMPOSITE davinci_enc_mngr.ch0_mode=ntsc'
waitrecv '#' 1 0
 
sendln 'setenv bootargs $(videoargs) console=ttyS0,115200n8 noinitrd rw root=/dev/nfs nfsroot=$(nfshost):$(rootpath),nolock ip=$(ipaddr) mem=120M'
waitrecv '#' 1 0
 
sendln 'tftpboot 0x80700000 uImage; bootm'
waitrecv '#' 1 0
Note: The use of parenthesis for variable substitution is being deprecated for new U-boot releases - use curly braces {} instead. Check http://www.denx.de/wiki/view/DULG/CommandLineParsing

Are there any DM355 examples?

Below are 4 macros for each of the boot options on DM355 - TFTP/NAND for kernel and NAND/NFS for file system):

;; Tera Term Macro
;; ============================================================================
;; file dm355_tftp_nfs.ttl
;; comments rename the serverip, rootpath and bootfile
;; ============================================================================
 
showtt 0
setsync 1
 
sendln 'setenv serverip xxx.xxx.xxx.xxx'
waitrecv '#' 1 0
 
sendln 'setenv nfshost $(serverip)'
waitrecv '#' 1 0
 
sendln 'setenv rootpath /home/user/target'
waitrecv '#' 1 0
 
sendln 'setenv videoargs video=dm355fb:vid0=720x480x16,2025K@0,0:vid1=720x480x16,2025K@0,0:osd0=720x480,1350K@0,0:osd1=720x480,1350K@0,0
waitrecv '#' 1 0
 
sendln 'setenv bootargs $(videoargs) console=ttyS0,115200n8 root=/dev/nfs rw nfsroot=$(nfshost):$(rootpath) ip=dhcp mem=116M'
waitrecv '#' 1 0
 
sendln 'setenv bootfile uImage'
waitrecv '#' 1 0
 
sendln 'dhcp;bootm'
waitrecv '#' 1 0
Note: The use of parenthesis for variable substitution is being deprecated for new U-boot releases - use curly braces {} instead. Check http://www.denx.de/wiki/view/DULG/CommandLineParsing
;; Tera Term Macro
;; ============================================================================
;; file dm355_tftp_nand.ttl
;; comments rename the serverip and bootfile
;; ============================================================================
 
showtt 0
setsync 1
 
sendln 'setenv serverip xxx.xxx.xxx.xxx'
waitrecv '#' 1 0
 
sendln 'setenv videoargs video=dm355fb:vid0=720x480x16,2025K@0,0:vid1=720x480x16,2025K@0,0:osd0=720x480,1350K@0,0:osd1=720x480,1350K@0,0
waitrecv '#' 1 0
 
sendln 'setenv bootargs $(videoargs) console=ttyS0,115200n8 root=/dev/mtdblock3 rw rootfstype=yaffs2 rw ip=dhcp mem=116M'
waitrecv '#' 1 0
 
sendln 'setenv bootfile uImage'
waitrecv '#' 1 0
 
sendln 'dhcp;bootm'
waitrecv '#' 1 0
Note: The use of parenthesis for variable substitution is being deprecated for new U-boot releases - use curly braces {} instead. Check http://www.denx.de/wiki/view/DULG/CommandLineParsing
;; Tera Term Macro
;; ============================================================================
;; file dm355_nand_nfs.ttl
;; comments rename the serverip and rootpath
;; ============================================================================
showtt 0
setsync 1
 
sendln 'setenv serverip xxx.xxx.xxx.xxx'
waitrecv '#' 1 0
 
sendln 'setenv nfshost $(serverip)'
waitrecv '#' 1 0
 
sendln 'setenv rootpath /home/user/target'
waitrecv '#' 1 0
 
sendln 'setenv videoargs video=dm355fb:vid0=720x480x16,2025K@0,0:vid1=720x480x16,2025K@0,0:osd0=720x480,1350K@0,0:osd1=720x480,1350K@0,0
waitrecv '#' 1 0
 
sendln 'setenv bootargs $(videoargs) console=ttyS0,115200n8 root=/dev/nfs rw nfsroot=$(nfshost):$(rootpath) ip=dhcp mem=116M'
waitrecv '#' 1 0
 
sendln 'nboot 0x80700000 0 0x400000;bootm'
waitrecv '#' 1 0
Note: The use of parenthesis for variable substitution is being deprecated for new U-boot releases - use curly braces {} instead. Check http://www.denx.de/wiki/view/DULG/CommandLineParsing
;; Tera Term Macro
;; ============================================================================
;; file dm355_nand_nand.ttl
;; ============================================================================
showtt 0
setsync 1
 
sendln 'setenv videoargs video=dm355fb:vid0=720x480x16,2025K@0,0:vid1=720x480x16,2025K@0,0:osd0=720x480,1350K@0,0:osd1=720x480,1350K@0,0
waitrecv '#' 1 0
 
sendln 'setenv bootargs $(videoargs) console=ttyS0,115200n8 root=/dev/mtdblock3 rw rootfstype=yaffs2 rw ip=dhcp mem=116M'
waitrecv '#' 1 0
 
sendln 'nboot 0x80700000 0 0x400000;bootm'
waitrecv '#' 1 0
Note: The use of parenthesis for variable substitution is being deprecated for new U-boot releases - use curly braces {} instead. Check http://www.denx.de/wiki/view/DULG/CommandLineParsing

Are there any DM6467 examples?

Below is an example ttl script for users with a switch/router. To reiterate one of the advantages of using a ttl script is that you can share boards between team members without wrenching their boot settings.

This ttl script has been tested in the DVSDK 1.40 environment.

Naturally replace the serverip with whatever /sbin/ifconfig shows as your IP address.

showtt 0
setsync 1
 
sendln 'setenv serverip 158.123.45.678'
waitrecv '#' 1 0
 
sendln 'setenv nfshost $(serverip)'
waitrecv '#' 1 0
 
sendln 'setenv ipaddr dhcp'
waitrecv '#' 1 0
 
sendln 'setenv rootpath /home/user/workdir/filesys_dm6467'
waitrecv '#' 1 0
 
sendln 'setenv bootargs console=ttyS0,115200n8 noinitrd rw root=/dev/nfs nfsroot=$(nfshost):$(rootpath),nolock ip=$(ipaddr) mem=120M davincihd_capture.channel0_numbuffers=4'
waitrecv '#' 1 0
 
sendln 'setenv bootfile uImage.DM6467'
waitrecv '#' 1 0
 
sendln 'dhcp;tftpboot;bootm'
waitrecv '#' 1 0


Here is a DM6467T EVM Teraterm macro file for DVSDK 3.10. The macro provides the following options:

; Macro for Tera Term
; DM6467T EVM - DVSDK v3.10
; Texas Instruments
; Authors: Prateek Bansal, Scott Specker
 
; Uncomment below line if using from command line. Note '/C=1' indicates COM1!! For COM2 use '/C=2'
; connect '/C=1'
;
; showtt Show TeraTerm window when inputting commands
showtt 1
; Synchronous mode - wait for > before next command is sent
setsync 1
 
; Disable autoload TFTP when invoking dhcp command to get IP address
sendln 'setenv autoload no'
waitrecv '>' 1 0
 
; Set boot file if booting kernel via TFTP
sendln 'setenv bootfile uImage'
waitrecv '>' 1 0
 
; Video settings for DVSDK 3.10 for DM6467T EVM
sendln 'setenv videocfg vpif_display.ch2_numbuffers=0 vpif_display.ch3_numbuffers=0'
waitrecv '>' 1 0
 
; static ip  (You can chose to hardcode the static IP address)
sendln 'setenv ipaddr 192.168.1.111'
waitrecv '>' 1 0
sendln 'setenv gateway 192.168.1.1'
waitrecv '>' 1 0
sendln 'setenv netmask 255.255.255.0'
waitrecv '>' 1 0
sendln 'setenv static_ip $ipaddr:$gateway:$netmask::::off'
waitrecv '>' 1 0
 
; Bootcmd parameters for booting kernel from Flash or via TFTP
sendln 'setenv bootcmd_flash nboot 80700000 0 640000\;bootm'
waitrecv '>' 1 0
sendln 'setenv bootcmd_tftp tftp\;bootm'
waitrecv '>' 1 0
 
; Shared NFS directory path
defaultNFSpath='/home/user/workdir/filesys'
msg = 'Use Default NFS Path Address: '
strconcat msg defaultNFSpath
yesnobox msg 'DaVinci Setup'
if result then
	sendln 'setenv nfspath /home/user/workdir/filesys'
	waitrecv '>' 1 0
else
	inputbox 'Enter NFS Path:' 'DaVinci Setup'
 
	sendln 'setenv nfspath ' inputstr
	waitrecv '>' 1 0rebooroo
endif
 
; Boot with Static IP address or DHCP configuration for DM6467 EVM
yesnobox 'Boot Static or Dynamic? [Yes=Static, No=Dynamic(dhcp)]'  'DaVinci Setup'
if result then
	sendln 'setenv myip $static_ip'
	waitrecv '>' 1 0
else
	sendln 'dhcp'
	waitrecv '>' 1 0
	sendln 'setenv myip dhcp'
	waitrecv '>' 1 0
endif
 
; TFTP Server and NFS host IP Address - for loading uImage and NFS directory
defaultServerip='192.168.1.102'
msg = 'Use Default TFTP Server IP Address: '
strconcat msg defaultServerip
yesnobox msg 'DaVinci Setup'
if result then
	sendln 'setenv serverip ' defaultServerip
	waitrecv '>' 1 0
else
	inputbox 'Enter Server IP Address:' 'DaVinci Setup'
	sendln 'setenv serverip ' inputstr
	waitrecv '>' 1 0
endif
 
; Set NFS host address same as serverip
sendln 'setenv nfshost $serverip'
waitrecv '>' 1 0
 
 
; Boot HDD or NFS filesystem
yesnobox 'Boot using Root from HDD or NFS? (Yes=HDD, No=NFS)'  'DaVinci Setup'
if result then
	sendln 'setenv bootargs_hdd mem=76M console=ttyS0,115200n8 noinitrd ip=$myip root=/dev/hda1'
	waitrecv '>' 1 0
	sendln 'setenv bootargs $bootargs_hdd $videocfg'
	waitrecv '>' 1 0
else
	sendln 'setenv bootargs_nfs mem=76M console=ttyS0,115200n8 noinitrd rw ip=$myip root=/dev/nfs nfsroot=$nfshost:$nfspath,nolock'
	waitrecv '>' 1 0
	sendln "set bootargs $bootargs_nfs $videocfg"
	waitrecv '>' 1 0
endif
 
; Boot kernel from Flash or via TFTP
yesnobox 'Boot Kernel from Flash or via TFTP? (Yes=Flash, No=TFTP)'  'DaVinci Setup'
if result then
	sendln 'set bootcmd $bootcmd_flash'
	waitrecv '>' 1 0
else
	sendln 'set bootcmd $bootcmd_tftp'
	waitrecv '>' 1 0
endif
 
; Save environment variables
yesnobox 'Save uboot environment variables?' 'DaVinci Setup'
if result then
	sendln 'saveenv'
	waitrecv '>' 1 0
endif
 
; Boot linux or go to uboot prompt
yesnobox 'Boot Linux now?' 'DaVinci Setup'
if result then
    sendln 'boot'
else
	setdlgpos 200 200
	msg='Use the "boot" command when you want to boot the DVEVM'
	;statusbox 'Message' 'Title'
	statusbox msg 'Boot later...'
	pause 2
	closesbox
endif
 
showtt 1

Note: The use of parenthesis for variable substitution is being deprecated for new U-boot releases - use curly braces {} instead. Check http://www.denx.de/wiki/view/DULG/CommandLineParsing

What about OMAP-L1 TeraTerm Scripts?

Are there any OMAPL137 examples?

Below is an example ttl script for users with a switch/router and NFS server. To reiterate one of the advantages of using a ttl script is that you can share boards between team members without wrenching their boot settings.

This ttl script has been tested in the SDK 1.00.00.10 environment and all directories and filenames match the default installation procedure as listed in the Installing the Software for OMAP-L137

Note: for OMAPL137 you must set the delay as mentioned in the What is a TeraTerm INI? section

; Keep the VT window open while executing macro
showtt 1
 
; Set the synchronous mode
setsync 1
 
; Set the title to make easier identification between boards
settitle 'OMAPL137'
 
; set tftp server ip address
sendln 'setenv serverip 192.168.1.89' ;CHANGE 192.168.1.89 TO MATCH YOUR CONFIGURATION!!!
 
; set nfs server ip address
sendln 'setenv nfshost ${serverip}'
 
; set nfs rootpath
sendln 'setenv rootpath /home/<useracct>/workdir/filesys' ;CHANGE <useracct> TO MATCH YOUR CONFIGURATION!!!
 
; set kernel command line argument
sendln 'setenv bootargs console=ttyS2,115200n8 noinitrd rw ip=dhcp root=/dev/nfs nfsroot=${nfshost}:${rootpath},nolock mem=32M'
 
; choose kernel image file name
sendln 'setenv bootfile uImage'
 
; obtain the IP via dhcp server and boot the board!
sendln 'dhcp;bootm'
 
; end of macro file

The script below works with an USB pendrive that should meet the requirements below. Check the <LSP_02.20_OMAP-L137_User_Guide.pdf> and this topic for additional details.

; Keep the VT window open while executing macro
showtt 1
 
; Set the synchronous mode
setsync 1
 
; needed because of the slower operations usb start and fatload
PromptUboot = 'U-Boot > '
 
; Set the title to make easier identification between boards
settitle 'OMAPL137'
 
; check if USB is alive and which devices are on
sendln 'usb start'
wait PromptUboot
 
; load the kernel image to memory
sendln 'fatload usb 0:1 0xC0700000 uimage'
wait PromptUboot
 
; set kernel command line argument
sendln 'setenv bootargs console=ttyS2,115200n8 noinitrd rw ip=dhcp root=/dev/sda2 rootfstype=ext2 mem=32M' ;USB BOOT
 
; choose kernel image file name
sendln 'setenv bootfile uImage'
 
; boot the board!
sendln 'bootm'
 
; end of macro file

Note: The command usb start sometimes hangs on the message scanning bus for storage devices.... If this happens to you, stop the macro from executing, reset the board and reload the script file.

The script below works with a linux kernel in SPI and a MMC/SD card that contains the root filesystem

; Keep the VT window open while executing macro
showtt 1
 
; Set the synchronous mode
setsync 1
 
; Set the title to make easier identification between boards
settitle 'OMAPL137'
 
; needed because of the slower SPI Flash operations
PromptUboot = 'U-Boot > '
 
; set kernel command line argument
sendln 'setenv bootargs console=ttyS2,115200n8 noinitrd rw ip=dhcp root=/dev/mmcblk0p1 rootfstype=ext2 mem=32M' ;MMC/SD BOOT
 
; select the SPI Flash memory
sendln 'sf probe 0'
wait PromptUboot
 
; load kernel image to RAM address 0xc0700000...
sendln 'sf read 0xc0700000 0x1e0000 0x220000'
wait PromptUboot
 
; ...and boot the board!
sendln 'bootm'
 
; end of macro file

Are there any OMAPL138 examples?

Below is an example ttl script for users with a switch/router and NFS server. To reiterate one of the advantages of using a ttl script is that you can share boards between team members without wrenching their boot settings.

This ttl script has been tested in the SDK 1.00.00.08 environment and all directories and filenames match the default installation procedure as listed in the GSG: Installing the Software for OMAP-L1

; Keep the VT window open while executing macro
showtt 1
 
; Set the synchronous mode
setsync 1
 
; Set the title to make easier identification between boards
settitle 'OMAPL138'
 
; The timeout between lines is 1 second
;timeout = 1
 
; set tftp server ip address
sendln 'setenv serverip 192.168.1.89' ;CHANGE 192.168.1.89 TO MATCH YOUR CONFIGURATION!!!
 
; set nfs server ip address
sendln 'setenv nfshost ${serverip}'
 
; set nfs rootpath
sendln 'setenv rootpath /home/<useracct>/workdir/filesys' ;CHANGE <useracct> TO MATCH YOUR CONFIGURATION!!!
 
; set kernel command line argument
sendln 'setenv bootargs console=ttyS2,115200n8 noinitrd rw ip=dhcp root=/dev/nfs nfsroot=${nfshost}:${rootpath},nolock mem=32M'
 
; choose kernel image file name
sendln 'setenv bootfile uImage'
 
; obtain the IP via dhcp server and boot the board!
sendln 'dhcp;bootm'
 
; end of macro file
What about using a DLP Pico Projector?

Beagle example

; Tera Term script for using DLP Pico Projector as display on Beagle
; File system on partition 2 of SD card - you may need to modify the DSS based on your kernel
; The first bootargs are for 2.6.28, and second set for 2.6.29
setsync 1
 
sendln 'mmcinit'
waitrecv '#' 1 0
 
sendln 'setenv bootargs console=ttyS2,115200n8 root=/dev/mmcblk0p2 rw rootwait omap-dss.def_disp=dvi omapfb.video_mode=640x480MR-16@60 omapfb.vram=4M,4M,4M mem=80M'
;sendln 'setenv bootargs console=ttyS2,115200n8 root=/dev/mmcblk0p2 rw rootwait omapdss.def_disp=dvi omapfb.mode=dvi:640x480MR-16@60 omapfb.vram=0:4M,1:4M,2:4M mem=80M'
waitrecv '#' 1 0
 
sendln 'setenv bootcmd mmcinit;fatload mmc 0 80300000 uImage;bootm 80300000'
waitrecv '#' 1 0
What is a TeraTerm INI?

When TeraTerm starts, it runs TERATERM.INI to setup the console. Once you have set your serial terminal to the correct baude rate (via "Setup->Serial") on COM1 (via "Setup->General->Default Port"), you can save the setup via "Setup->Save Setup." Save this setup in the TeraTerm Installation directory by overwriting TERATERM.INI. Now your TeraTerm will be setup correctly every time you start it.

To run the above scripts, you may need to add a line delay of 100ms (otherwise the lines can become concatenated) by setting the Transmit delay to 100 ms/line (via "Setup->Serial"). You'll probably want to save this modification in TERATERM.INI to avoid having to modify it every time you start TeraTerm.

Important additions to macro language since version 4.52

Generally you should use version 4.77 or later as there were important additions to macro language in each of recent versions (starting from 4.52):

2006.2.10 (Ver 4.27)

2006.10.09 (Ver 4.46)

2007.8.8 (Ver 4.53)

2007.9.30 (Ver 4.54)

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

2007.12.4 (Ver 4.56)

2008.1.15 (Ver 4.57)

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)

2009.7.5 (Ver 4.63)

2009.11.10 (Ver 4.64)

2010.2.20 (Ver 4.65)

2010.5.31 (Ver 4.66)

2010.8.31 (Ver 4.67)

2011.3.5 (Ver 4.69)

Here is a 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 files 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
You can drag macro to the desktop so that each macro is represented by an icon.  Clicking on this icon will launch the macro.

This way you can have unique macros for each of you important servers so that you do not need to recreate environment and other preliminary steps manually for it.  That can save a lot of time and is simpler and more efficient then programming keyboard macros.


Top updates

Bulletin Latest Past week Past month
Google Search


NEWS CONTENTS

Old News ;-)

[Nov 20, 2014]  TeraTerm Macro language for dummies (or something like that)

Oct 21, 2012 | TeraTerm Support Forums
rgaiken Location: Wisconsin

So I'm attempting to consolidate what I know of the TeraTerm language into a single mega-post. If you have any knowledge that you think would be a valuable addition to this post, feel free to let me know.

Note that this is pretty much just an abridged form of the language reference tied into a somewhat cohesive format. Just because something isn't mentioned here doesn't mean it doesn't exist; check out the official language reference and search the forums to get a handle on some of TeraTerm's more advanced features. This is really not a full-fledged tutorial to take you from the very basics of computer literacy; if you have no prior programming experience this may be challenging to follow.

As a little precursor, if you happen to use Programmer's Notepad as your editor of choice, the NSIS Installer highlighting scheme matches fairly well with this scripting language. Vim users might be able to make use of this highlighting scheme (somewhat outdated, won't have latest keywords).

TeraTerm basics

So to start things off, let's deal with variables.

There are two types of variables: Strings (limited to 255 characters) , and Integers (Limited to ~ +/-2 billion) (want to go bigger?). The type is determined implicitly when the variable is created and cannot be altered afterwards.

Also, since TeraTerm 4.72, there are now arrays of both of these types (limited to 65536 indices per array)

 

Select all

  1. integerVariable=10 ; An Integer variable
  2. strVariable='asdf' ; A string variable
  3. strVariable2='0' ; Still a string variable
  4. integerVariable='asdf' ; ERROR!!!!!!
  5. integerVariable=2
  6. ; A little fun with arrays:
  7. intdim integerArray 10 ; Create an integer array of size 10
  8. integerArray[0]=10 ; Assigns the first element of the array to 0
  9. integerArray[10]=10 ; ERROR!!!!!
  10. ; It's almost exactly the same for strings, just using strdim instead:
  11. strdim strArray integerVariable ; Creates a string array that has the size given in integerVariable
  12. ; Also, by the way, the semicolon (;) is the character that denotes a comment; anything after it in a line has no effect on the running of your script (notice how I used the semicolon in a grammatically correct way in a sentence about semicolons ;-)

But variables by themselves are boring. The real basis of any programming language is the if statement. However an if statement by itself is somewhat boring, so let's go a little further and also show you a wait statement:

 

Select all

  1. wait 'value = 0' 'ERROR'
  2. if result=1 then
  3. ; value = 0 was received on the terminal
  4. elseif result=2
  5. ; ERROR was received on the terminal
  6. endif

The wait statement is one of the more or less unique features of TeraTerm. Essentially, it reads through all of the serial output that hasn't been parsed yet, and when one of the strings in its sensitivity list is found, it sets result to the index of that string and moves on. The documentation for the setsync command has a partial general overview for how TeraTerm internally works.

Note that you can also set a timeout for wait, and it will then only hold up the execution of the script for at most timeout.mtimeout seconds:

 

Select all

  1. timeout=1
  2. mtimeout=500 ; Set the timeout for 1.5 seconds
  3. wait 'Good' 'Bad'
  4. if result=0 then
  5. ; Neither good nor bad appeared in the terminal output during the 1.5 seconds
  6. endif

A nice counterpoint to the 'wait' command is the 'sendln' and 'send' commands. These guys do pretty much what their names suggest: they write stuff back out to the terminal (with sendln adding a newline at the end of its string).
A common use that I have for the wait/sendln pair is to send a series of commands to a machine.
For example, when sending a series of commands to a Linux box, it might look something like the following:
 

Select all

  1. wait 'root@localhost#'
  2. sendln 'command'
  3. wait 'root@localhost#'
  4. sendln 'command'
  5. wait 'root@localhost#'
  6. sendln 'command'

This ensures that the prior command has finished before you send the next command. The sendkcode command is also occasionally useful in some cases.

Note that the above code is somewhat ugly. If the prompt were to change (say from root@localhost to root@servername), I'd have to manually replace a bunch of lines. Since I'm lazy, the following format is much nicer:
 

Select all

  1. cmdPrompt='root@localhost'
  2. wait cmdPrompt
  3. sendln 'command'
  4. wait cmdPrompt
  5. sendln 'command'
  6. wait cmdPrompt
  7. sendln 'command'

That looks much nicer.

Looping

Branching is all well and good, but eventually you will want to do something that has some repetition in it. Teraterm has several more or less standard looping constructs

 

Select all

  1. do while i>0
  2.     i = i - 1
  3. loop
  4. do
  5.     i=i-1
  6. loop while i>0
  7. for j 1 10
  8.     i=j+i
  9. next
  10. until i > 10
  11.   i = i + 1
  12. enduntil
  13. while i>0
  14.   i = i - 1
  15. endwhile

I won't go into too much detail about all of these; TeraTerm probably has more looping constructs than is really healthy, but definitely keep in mind the 'for' loop, and the fact that the 'do while' loop can be done as a pre-test loop or a post-test loop. The 'break' command can also be used to escape from a loop before its condition triggers

Lastly for the basics is TeraTerm's goto command. Some people (especially those experienced with C and who have experienced the nightmares of spaghetti code) view gotos as positively evil and wish they could be nuked from every language in existence. Gotos can do just about anything, but typically not as nicely as one of the above looping structures. About the only place that gotos should really go is in error handling:
 

Select all

  1. wait 'Good' 'Bad'
  2. if result=2 goto ERROR
  3. ; Presumably, a bunch of non-related code goes here
  4. exit ; Typically, you don't want to execute the error code upon successful completion of the normal code, so this exits before doing that
  5. :ERROR
  6. ; Error-handling/messaging code goes here
  7. exit

TeraTerm and regular expressions

Regular expressions are an interesting creature in and of themselves. An old and relatively well-known quote about regular expressions (regexes) goes something like this:
 

Quote:

Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.


Regexes are a double-edged sword that allow you to do stuff with strings that would normally not be possible. Since I don't really want to go into all the nitty gritty, here's a link to wikipedia, as well as afairly-well-laid-out regex tutorial site. Note that TeraTerm has also posted a reference for the regex engine that they use, but that isn't really laid out for learning...

TeraTerm has several commands which use the power of regular expressions (let me know which one's I'm forgetting...):
 

Select all
  1. waitregex <string1 with regular expression> [<string2 with regular expression> ...]
  2. strmatch <target string> <string with regular expression>
  3. strreplace <strvar> <index> <regex> <newstr>

strmatch and strreplace are both relatively normal. You put your regular expression in, and TeraTerm works its magic.

waitregex is a beast that I've seen misused in these forums time and again. In many ways, it is identical to the wait command, just with regular expression support. The large difference is with regular expression matching. Regular expression matching is what happens when a regular expression with parenthesis triggers on a string. The result inside the string is then returned (in normal regular expressions, it is returned as \1, \2, \3, etc, while with TeraTerm, they are stored in the groupmatchstr1, groupmatchstr2,...,groupmatchstr9 variables).

An example is as follows:
 

Select all

  1. waitregex 'value = ([0-9]+)' 'ERROR'
  2. if result=1 then
  3.     str2int returnValue groupmatchstr1
  4. endif

Let's pick the above code fragment apart bit by bit.
First we have '[0-9]+' This regex essentially grabs the largest amount of consecutive characters that fall between 0 and 9. The parenthesis '(...)' are what initiate the grouping. With the parenthesis, the string that was caught by '[0-9]+' gets stored into groupmatchstr1. If the regular expression as a whole was triggered, the result will be one and the if statement will let the str2int command work its magic. The str2int command (and its counterpart, the int2str command) do exactly what their names suggest: convert between string and integer variables.

Thus, if the 'value = 5643' was received on the terminal, this code would set returnValue to 5643

Note that waitregex only works on the first 255 characters of a line, so anything further than that and you're going to have to find another way.

File input and output
My file I/O skills are minimal at best. Anything that you'd care to offer is gladly accepted
Also, don't forget about the ability to use logging commands in some cases (check out loginfo, logopen, logclose, logstart, logpause, and logwrite)

User input and output
Most of the commands used here are described in the Miscellaneous Commands section of the TTL Command Reference.

 

Select all

  1. messagebox <message> <title>

This is one of the most commonly-used UI-type commands of the macro language. It pops up a window with the title equal to <title>, and the content equal to <message>, with an Ok button at the bottom. Note that code beneath this command won't execute until Ok is clicked.


 

Select all

  1. yesnobox <message> <title>

This is almost identical to the messagebox, however rather than an Ok button, there's a Yes and a No button. If Yes is clicked, result=1, otherwise result=0


 

Select all

  1. inputbox <message> <title> [<default>]

The third of the *box commands that I use on a normal basis, this is like the messagebox command, but with an area that the user can type stuff in. That area is populated with <default> when the window first appears, and after the user clicks Ok, the variable 'inputstr' contains the value of that area.

Strings!!!
Fill this section with stuff for commands like sprintf2

Connecting to things other than serial ports and whatnot
I'm really not at all good with TeraTerm in this department. If someone else here has some wisdom to offer, feel free to drop it off here...

Any feedback is appreciated, both for my sake, and for all of the newbies out there. The main goal of this post is to be a one-stop learning reference for people who are just learning the language, as well as to facilitate the general usability of it through simple examples.

Good luck, bon apetit, hasta la vista, whatever. Just go out and make/break something...


Changelog:
10/24/2012 - Added a brief (unverified) description of arrays (I use a slightly older version of TT at work, and primarily use Linux at home currently, so I haven't had a chance to play around with these)
10/31/2012 - Added more formatting/hyperlinks and clarified a few points

Let's keep the suggestions coming! 
_________________
If one of my posts helped you out, do me a favor:
Next time anyone asks you for help, go out of your way to help them.

Thanks!

Teraterm Script to Automate Command entry

I wanted to create a script which when clicked on will log in to the node, run a list of commands located in a text file and save the output in a log file.

Initially I created a script using securecrt but I hit upon an hurdle. Some of the command output were many pages long and a '--More--' prompt appeared .

In some nodes like cisco routers this is not a problem. There is a command 'Terminal length 0' which allows you to print complete output for commands with long outputs like 'show run'. I was working on a linux based node and no such option existed. The script was unable to recognise this prompt. I had to manually hold down  the spacebar till the next prompt appeared.

This was solved in newer versions of securecrt with 'crt.screen.Readstring' command. However securecrt is not a freeware. So I searched for other alternatives and found TeraTerm.

Teraterm is an alternative to putty and securecrt.

You can download from

http://logmett.com/index.php?/download/tera-term-476-freeware.html

The command reference can be found here

http://ttssh2.sourceforge.jp/manual/en/macro/command/index.html

It has its own TTL scripting language but its  very powerful and easy to learn. Best part is its open source and freeware.

Below is what the script does.

The commands to be run are put in file commands.txt in path  D:\TTERMPRO313.The output will be created in same path with name log appended with current timestamp.

The first command in the commands.txt file is run and a log file is opened , then it waits for prompt --More-- or @CLA.

If '--More--' prompt is detected it sends '#32' (i.e. spacebar). If '@CLA'  prompt is detected it runs the next command. When all commands are run its done.

Below is the script.

; ******* LogMeTT Macro Template for command output************************************
;commands to be put in file commands.txt in path D:\TTERMPRO313
;log Output with current timestamp created in same path 
;hardcoded username and password (not recommended)
;connect to node with ip 82.56.56.7 using ssh2 with username a username ans password as password
connect '82.56.56.7 /ssh /2 /auth=password /user=username /passwd=password'
; Entering synchronous communication mode (useful in most cases)
setsync 1
;wait for the screen prompt @CLA
wait '@CLA'
;put the command file containing the list of commands in this path
setdir 'D:\TTERMPRO313'
changedir 'D:\TTERMPRO313'
;logfile will be created with below name and appended with current timestamp
gettime logfile "log-%Y%m%d-%H%M%S.txt"
;start logging
logopen logfile 0 0
fileopen commandfile 'commands.txt' 0
:looper2
filereadln commandfile statement
if result goto fclose2
sendln statement
:label2
wait '@CLA' '-More-'
if result=2 send #32 
if result=1 goto looper2
goto label2
:fclose2
fileclose commandfile
;stop logging
logclose
;************************************************************************************

[Jul 08, 2014] TTLEditor: Video Tutorial - YouTube

[Jul 08, 2014] Teraterm Scripts

Texas Instruments Embedded Processors Wiki

Tera Term is an opensource terminal emulator on MS-Windows commonly used by us developers. Tera Term supports a "rich" macro language that can help in automating user actions. These scripts usually remain personal - rarely shared.

In this page, I intend to share the basic scripts that can be used to automate common tasks in the Linux PSP release. The scripts were created with intentional hierarchy to maximize reuse (via inclusion) and minimize redundancy across scripts. Currently, these scripts apply to OMAP35x Linux PSP. But, can be extended easily to other platforms.

Needless to say, these scripts are open to enhancements.

Tera Term TTL Scripting example for CLI based devices

Tera Term Support forum by Boris Maisuradze

Tera Term TTL Scripting example for CLI based devices

GroupStudy.com - CCIE, CCNA, CCNP and other Cisco Certifications

 

I saw a discussion about Hyperterm and Tera Term a few weeks ago. I had no
idea so many people liked Tera Term as much as I did. For the record, I used
Tera Term the whole time I was studying except for the last 2 weeks before
my exam. Then I switched to Hyperterm just to get used to the look & feel.

I wrote a useful Tera Term macro. It assumes you are connected to your
terminal server and that you are using that to connect to your routers. This
macro assumes you have the terminal server and 5 other routers, but as you
can see its very  easy to add or subtract for the actual number of routers
you have.

This macro automatically gets the running-config and the ip routing table
from all your routers and places into a log file. What could be easier?!?!
It prompts you for the filename; the directory is in the first few lines of
the macro (and can be easily changed to whatever you want). You can easily
add other commands - I created other macros based on this one for IPX, DLSw,
etc.

I found this useful since as I studied each major topic I wanted to record
the results in case I had questions later or if I wanted to review topics.
Since it does everything automatically its also handy in cases such as if
you are studying BGP. You can alter the preference, run the macro, alter the
MED, run the macro, etc. In that case you'd probably also want to include
show ip bgp commands.

My comments and the actual macro are included below. Hopefully this will
save some folks some time - you never have enough of that! If you don't
currently use Tera Term you may want to consider it, I believe it can be
downloaded from www.tucows.com.

Robert M. Webber
Senior Network Consultant
CCIE 6922
Callisma - Building Your Network of the Future. Today.
Cell: 508-254-6400
Pager: 877-964-8111
http://www.callisma.com

To use the macro, simply copy the macro into an editor such as notepad and
save it. I recommend saving it with a ".ttl" extension since that is what
Tera Term will look for by default. I keep my macros right in the Tera Term
default directory, c:\Program Files\TTERMPRO. This macro gets used when you
are connected to your terminal server and have already established
connections to your routers via the terminal server.

To specify the directory you want to place your logs in, simply edit line 2
(and then cut & paste that line into line 6 and 13).  The directory you see
is what my laptop uses for its "My documents" folder; obviously you can
change this to whatever you want. You can use whatever you want for the
filename (you aren't restricted to 8 letters). So you can call your log
"OSPF with area summarization.doc" if you want. I usually use the .doc
extension so Word will bring it up if I want to review it later.

The first 16 lines ask for the filename and check to make sure it doesn't
already exist.

Note that you must be in enable mode for this to work since Tera Term is
waiting for the "#" to come back from the router to let it know the router
is ready. The commands:

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

are what get sent to each router. Here is where you can enter whatever
commands you want. I included the "pause 16" (Tera Term waits 16 seconds)
just to make sure Tera Term doesn't overrun the router while the router is
generating its config. Tera Term is supposed to wait for the "#" before
going on, but I found this just seemed to work better.

the commands

send "1"
sendln #13
wait "#"

tell your terminal server to connect to session 1, and send a return. The
return simply gets the router to return its prompt.

The command

sendln #30#$78
wait "#"

sends the ctrl-shift-6 x so that you break back to the term server. As you
can see you then issue a "2" (going to the second connection) and repeat the
whole process. So just adjust these lines based on the number of routers you
are working with.

Good luck!
Here's the macro:
--------------------------
timeout = 120
directory = "C:\Documents and Settings\RMW1\My Documents\My Router configs\"
inputbox "Name of log file for this test:" "CCIE Here I come!"
strconcat directory inputstr
logfilename = directory
directory = "C:\Documents and Settings\RMW1\My Documents\My Router configs\"
:search_logfile
filesearch logfilename
if result=0 goto openlog
 inputbox "Enter new filename:" "File already exists!"
 strconcat directory inputstr
 logfilename = directory
 directory = "C:\Documents and Settings\RMW1\My Documents\My Router
configs\"
 goto search_logfile
:openlog
logopen logfilename 1 1

sendln "show clock"
wait "#"

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

send "1"
sendln #13
wait "#"

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

sendln #30#$78
wait "#"
send "2"
sendln #13
wait "#"

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

sendln #30#$78
wait "#"
send "3"
sendln #13
wait "#"

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

sendln #30#$78
wait "#"
send "4"
sendln #13
wait "#"

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

sendln #30#$78
wait "#"
send "5"
sendln #13
wait "#"

sendln "term length 0"
wait "#"
sendln "show running-config"
pause 16
sendln "show ip route"
wait "#"
sendln "term length 42"
wait "#"
pause 1

sendln #30#$78
wait "#"

logclose

_______________________________________________________
To unsubscribe from the CCIELAB list, send a message to
majordomo@xxxxxxxxxxxxxx with the body containing:
unsubscribe ccielab

[Jun 03, 2011] Power of Tera Term

May 7, 2007 | Extreme Networking

Tera Term is easily one of the most powerful free Terminal Emulation Software that I have come across and the power of it lies in its scripting language TTL. Of-course, it is not as extensive and capability rich as Perl but for a non-programmer, a browse through a single help file on TTL language is all it takes to create wonderful scripts that could make his/her life easier in maintaining huge networks.

The capabilities are limitless and if you could find better ways of enhancing the following script, please come forward and do your bit.

The purpose of the script is for terminal configuration of repetitive commands in multiple terminal enabled devices at once but sequentially without human intervention.

The other purpose of the script is to fetch terminal information from multiple terminal enabled devices at once but sequentially without human intervention.

The script is primarily designed for working with Cisco devices which can be configured using terminal emulation and which has a Command Line Interface ( CLI ).

The Procedure for execution of the script is as follows:

P.S.: While fetching configuration from any device like that of Cisco, please make sure to keep the terminal length to zero so that the device prompt appears immediately after the execution of the command.

Please give your feedbacks to make it better.

Below is the script for use with Tera Term. Just copy & paste the below code in a notepad and save it with a TTL extension.


;#######################################################
;Version 3.2 (Untested Beta Version)
;Created on 25/03/2007
;For Tera Term Macro Use Only
;Created originally for Cisco Switch & Routers.
;Customizable script, please feel free to edit it.(In fact you have to edit it)
;For usage, execute ttpmacro.exe and select this script
;Write all the ip addresses in sequential order in a file by the name of 'ip.txt'
;Write all the commands in sequential order in a file by the name of 'commands.txt'
;and place the text files in the directory as set by the 'setdir' keyword.
;Complaints and suggestions for improvement welcome.
;Please feel free to take it to the next level and share it with others.
;#######################################################
;######################################################
;Main Script
;######################################################
timeout = 5
dirname = 'E:\Program Files\TTERMPRO313'
setdir dirname
fileopen addressfile 'ip.txt' 0
inputbox 'Username:' 'Username Prompt'
Username = inputstr
passwordbox 'Password:' 'Password Prompt'
Password = inputstr
yesnobox 'Is enable password authentication required?' 'Enable Password Question'
if result=0 then
goto jumper1
endif
passwordbox 'Enable Password:' 'Enable Password Prompt'
Enable = inputstr
:jumper1
yesnobox 'Would you like to log the output?' 'Logging'
Logger = result
if Logger = 0 then
goto looper1
endif
inputbox 'Directory path & name followed by \' 'Logging Directory'
loggerpath = inputstr
dirmaker = 'cmd /C md '
strconcat dirmaker loggerpath
exec dirmaker
:looper1
filereadln addressfile ip
connect ip
if result = 1 then
goto fclose1
endif
wait 'Username:' 'Password:' '>' 'login:'
if result = 0 then
call terminator
goto looper1
elseif result = 1 then
goto jumper4
elseif result = 2 then
goto jumper5
elseif result = 3 then
goto jumper6
elseif result = 4 then
goto jumper4
endif
:jumper4
sendln Username
wait 'Password:'
:jumper5
sendln Password
if Logger = 0 then
goto jumper2
endif
loggerfile = loggerpath
strconcat loggerfile ip
logopen loggerfile 0 0
loggerfile = ''
:jumper2
wait '#' '>'
if result = 0 then
call terminator
elseif result = 1 then
call commander
call terminator
elseif result = 2 then
:jumper6
call enabler
call commander
call terminator
endif
goto looper1
:fclose1
fileclose addressfile
closett
end
;################################################
;Enabler is a sub-routine which provides enable password authentication.
;################################################
:enabler
setdir dirname
sendln 'enable'
wait 'Password:'
sendln Enable
return
;#####################################
;Commander is a sub-routine which executes the
;commands placed in 'commands.txt' file
;#####################################
:commander
setdir dirname
fileopen commandfile 'commands.txt' 0
:looper2
filereadln commandfile statement
if result goto fclose2
sendln statement
wait '#' '>'
if result = 2 then
goto fclose2
endif
goto looper2
:fclose2
fileclose commandfile
return
;###########################################
;Terminator is a sub-routine which provides terminal closure and
;passing the control to the main sub-routine for loop completion.
;###########################################
:terminator
beep
if Logger = 0 then
goto jumper3
endif
logclose
:jumper3
closett
return
;###########################################

http://logmett.com/forum/viewtopic.php?t=1085

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?

Select all

  1. ;°°°°°°°°°°°°°°° Conf Parameters °°°°°°°°°°°°°
  2.  
  3. username='XXXXX' ; username for connection
  4. password='YYYYYY' ; password for connection
  5. ip_address='IP_TEST.txt'; file with ip addresses of the routers to analyze
  6. timeout=5; timeout
  7. Sedi='indirizzi.txt'; file containing results
  8.  
  9.  
  10. ;°°°°°°°°°°°°°°°° APERTURA FILE CONTENENTE IP °°°°°°°°°
  11. ; Opening file with addresses
  12.  
  13.     fileopen fhandle Ip_address 0
  14.     filecreate fh Sedi
  15.    
  16. ;°°°°°°°°°°°°°°°° INIZIO LOOP °°°°°°°°°°°°°°°°°°°°°°°°
  17. ; Initial Loop
  18.  
  19.     :loop
  20.         filereadln fhandle ip_address
  21.         if result goto fine
  22.         flushrecv
  23.  
  24. ;°°°°°°°°°°°°°°°° CONNESSIONE °°°°°°°°°°°°°°°°°°°°°°°°°
  25. ; TT connects to one of the addresses in the list specified above
  26.    
  27.      connect ip_address
  28.  
  29. ;°°°°°°°°°°°°°°°° INVIO USERNAME °°°°°°°°°°°°°°°°°°°°°°
  30. ; Routine for sending username to host
  31.  
  32.     wait 'Username:'
  33.        if result=0 then
  34.         space = '_'
  35.         strconcat Ip_address space
  36.         strconcat Ip_address 'non connessa'
  37.         filewriteln fh ip_address
  38.             goto prossimo
  39.        endif
  40.         sendln username
  41.  
  42. ;°°°°°°°°°°°°°°°° INVIO PASSWORD °°°°°°°°°°°°°°°°°°°°°°
  43. ; Routine for sending password to host
  44.  
  45.     wait 'Password:'
  46.        if result=0 then
  47.         space = '_'
  48.         strconcat Ip_address space
  49.         strconcat Ip_address 'Tacacs non funzionante'
  50.         filewriteln fh ip_address
  51.         goto prossimo
  52.        endif
  53.        setsync 1
  54.     sendln password
  55.        setsync 0
  56.    
  57. ;°°°°°°°°°°°°°°°° CONTROLLO LINEA BGP °°°°°°°°°°°°°°°°°°°°°°
  58. ; TT sends commands for checking BGP links
  59. ;°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
  60.  
  61.  
  62.        flushrecv                       ;ensure nothing is in the buffer
  63.        sendln 'terminal length 0'  
  64.        sendln 'sh bgp a s'
  65.             for i 1 16
  66.             recvln           ;skip past technobabble
  67.                next
  68.                recvln
  69.                filewriteln fh inputstr  ;now save two relevant lines in a file
  70.                recvln
  71.                filewriteln fh inputstr
  72.         goto prox
  73.  
  74. ;°°°°°°°°°°°°°°°° DISCONNESSIONE  con HOST °°°°°°°°°°°°°°°°
  75. ; Disconnect from the host
  76.  
  77.     sendln 'exit'
  78.  
  79. ;°°°°°°°°°°°°°°°°     LOOP     °°°°°°°°°°°°°°°°°°°°°°°°°°°°
  80. ;Loop Procedure
  81.  
  82.     :prox
  83.         pause 1
  84.         disconnect
  85.         closett
  86.         goto loop
  87.  
  88. ;°°°°°°°°°°°°°°°°° FINE PROGRAMMA °°°°°°°°°°°°°°°°°°°°°°
  89. ; Close TT after ll IP have been processed
  90.  
  91.     :end
  92.         fileclose fhandle
  93.         end
  94.  

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.

[Mar 16, 2007] TeraTerm Support Forums View topic - First step to Tera Term Macros

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

====
 

boris
Guru


Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
 

Posted: Fri Mar 16, 2007 6:37 pm    Post subject: Reply with quote

boris wrote:
Depending on the number of switches different approaches can be taken. Can you say roughly how many switches you need to connect to?

About 600 Switches :s

Cheers,

Posted: Fri Mar 16, 2007 7:16 pm    Post subject: Reply with quote

TeraTerm macro can definitely help you but writing such script is not an easy task. I'd suggest you to approach it in few steps.

Start with writing telnet connection macro script to establish connection to your access router in HQ. You can use connection template from LogMeTT or sample code from one of the topics in these forums.

Then develop your script further to establish the second connection.

Step 3 will be to get familiar with opening and closing log files from macro. Here you can also add your "show tech" command.

Once you get to this point your macro will be able to reach one of your Cisco-s collect printout and save it into local file.

Then comes the tricky part. You need to store IP addresses of all your 600 switches in plain text file and run your macro in the loop where every execution will be using one IP from your IP list. Similar issue was discussed not long ago on our forums; just do some search and reading here. 2 more files that will help you are macro.hlp and LogMeTT.chm. You will find them both in TeraTerm package. Finally do not forget to give different file names to each log file. You probably can build log name from IP address and current time stamp. Check code snippets in our forums for the example.
_________________
Thanks.
Best regards,
// Boris

linkstate
Newbie


Joined: 16 Mar 2007
Posts: 7

 

Posted: Fri Mar 16, 2007 8:24 pm    Post subject: Reply with quote

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,

boris
Guru


Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
 

Posted: Sat Mar 17, 2007 6:22 am    Post subject: Reply with quote

Do you have word 'telnet' followed by IP address on each line of your file.txt?
_________________
Thanks.
Best regards,
// Boris
linkstate
Newbie


Joined: 16 Mar 2007
Posts: 7

 

Posted: Sat Mar 17, 2007 2:45 pm    Post subject: Reply with quote

No. Just the ip addresses. why ? is it supposed to ?
boris
Guru


Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
 

Posted: Sat Mar 17, 2007 5:03 pm    Post subject: Reply with quote

The same way as you do
Quote:
sendln'telnet 172.23.128.11'
earlier in your script, you need to pass method of connection and IP address in
Quote:
sendln line
Content of variable line is one string of your file.txt. If file does not contain words 'telnet' than you get as the result
 
Code:
sendln  172.23.x.y  ; <- whatever IP you have
which is the same as if you would type only IP address at command prompt without mentioning whether you need telnet, ssh, rlogin etc.

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,
// Boris
linkstate
Newbie


Joined: 16 Mar 2007
Posts: 7

 

Posted: Sun Mar 18, 2007 10:46 am    Post subject: Reply with quote

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 assistance

boris
Guru


Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
 

PostPosted: Sun Mar 18, 2007 11:11 am    Post subject: Reply with quote

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,
// Boris
linkstate
Newbie


Joined: 16 Mar 2007
Posts: 7

 

PostPosted: Sun Mar 18, 2007 11:18 am    Post subject: Reply with quote

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

exit

boris
Guru


Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
 

PostPosted: Sun Mar 18, 2007 2:48 pm    Post subject: Reply with quote

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,
// Boris
 

IshmaelCallMe
Coach


Joined: 25 Jan 2006
Posts: 119
Location: Denver, Colorado, USA
 

PostPosted: Mon Mar 19, 2007 6:53 am    Post subject: Reply with quote

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.
boris

Guru

Joined: 08 Jan 2005
Posts: 496
Location: Seattle, WA, USA
Mon Mar 19, 2007 7:14 am    Post subject: Thanks, I missed that

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
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,
// Boris

IshmaelCallMe
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.

Tera Term output to text file - General Help and Support - AutoIt Forums

Recommended Links

Tera Term Scripting, need help developing a macro - Stack Overflow

TeraTerm Support Forums • View topic - TeraTerm Macro language for dummies (or something like that)

TeraTerm Support Forums • View topic - Macro for SSH

TeraTerm Support Forums • View topic - This SSH connection macro doesn't work - (Solved!)

Good source of inspiration can also be

Forums

 

TTL  reference

TTL is a simple interpreted language like BASIC. To learn TTL quickly, study the sample macro files in the distribution package and the command reference.

 

Command index

Communication commands

Control commands

String operation commands

File operation commands

Password commands

Miscellaneous commands




Etc

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit exclusivly for research and educational purposes.   If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least


Copyright © 1996-2014 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. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. 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.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting hosting of this site with different providers to distribute and speed up access. Currently there are two functional mirrors: softpanorama.info (the fastest) and softpanorama.net.

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.

Last modified: November 21, 2014