Running Scripts within Minicom

ketty wanted to use minicom scripts originally to create time stamps for events for sensor testing (since the microcontroller cannot easily keep time). However, minicom scripting can be extended to run shell terminal commands within minicom. With limited documentation on this topic, finding out how to run scripts from minicom was difficult and the few example code out there all involve login scripts so they did not cater to what was needed. After extensive researching and playing around, ketty has wrote a “working” script that gets the job done but probably doesn't contain best scripting practices.

Runscript: Minicom's Built-in Script Interpreter

Minicom has it's own script interpreter called runscript. It is possible to use other script programs such as kermit and expect (tcl/tk), but these require installation of extra packages and require the user to learn a whole new scripting language. Runscript interpreter for minicom, on the other hand, is simple to code but it lacks features. The script is mainly used for login sessions and is probably only meant to be run for a few minutes at the begin of a minicom session. Therefore, the available commands were limited in runscript. For a full list of commands run “man runscript” in the terminal.

Example: Minicom Timestamp Script

This script was written to time stamp sensor events in order to log data for initial testing. It is a mixture of runscript and shell script. Runscript is similar to BASIC with goto labels.

Important Runscript Commands

"Timeout"

Notice the timeout of 2000000000 seconds. This is probably bad programming but since runscripts are intended for login sessions, the finite default timeout of 120 seconds would need to be extended for extensive logging/update purposes. The goal is for minicom to log for as long as possible.

"Expect"

The expect command acts like a switch statement. When a string is detected, the corresponding command is executed. The expect function also has a timeout of 60 seconds. Since we're logging events and want to keep on expecting, we can either set the timeout to a huge number again or go back to the main label.

"!"

! (with a space after) signals a shell command. Notice in the code below, the time stamp is inserted into a file along with a string using the $echo command.

#do not time out. we want to keep on logging
timeout 2000000000

main:
       #Detect incoming strings!
	expect {
	  "Switch 1" 		gosub log1
	  "Switch 2"		gosub log2
	}
	goto main
log1:
	! echo "`date` switch 1 was pressed! \r\n" >> timelog.txt 
	return

log2:
	! echo "`date` switch 2 was pressed! \r\n" >> timelog.txt 
	return

For other commands in runscript, type the following into your Linux terminal:

man runscript

Further Runscript Applications

Eventually, instead of putting event logs into a text file, we want to upload data onto a webpage. To do this, we want to maybe call another program that would update a webpage like the one cattykid has written here. Using the ”!” command, we can write some shell commands that call such a program and also pass it some simple parameters.

 
Back to top
projects/the_efficient_lounge/minicom.txt · Last modified: 2010/01/28 02:28 by ketty
 
 
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0