1comgt(1)                    General Commands Manual                   comgt(1)
2
3
4

NAME

6       comgt   -  Option GlobeTrotter GPRS/EDGE/3G/HSDPA  and Vodafone 3G/GPRS
7       datacard control tool
8

SYNOPSIS

10       comgt -d device -ehstvVx script
11

OPTIONS

13            -d device
14                      set the device to be used to communicate with the  data-
15                      card.   If  not  specified  then  comgt  trys /dev/noz2,
16                      /dev/ttyUSB2 and then
17
18            -e
19                      turn on serial communications echo.
20
21            -h
22                      display summary help and exit.
23
24            -s
25                      don´t run the internal default script before an external
26                      script.
27
28            -t
29                      change to an alternate line terminator (default "0).
30
31            -v
32                      run  in  verbose  mode.  This traces scripts as they are
33                      executed.  It is intended to help in debugging scripts.
34
35            -V
36                      Print Version information.
37
38            -x
39                      for internal and  external  scripts,  any  reference  to
40                      115200  baud  is converted to 57600.  This is useful for
41                      data cards that don't like 115200 baud such as the  Glo‐
42                      beTrotter EDGE.
43

DESCRIPTION

45       comgt  is a scripting language interpreter useful for establishing com‐
46       munications on serial lines and through PCMCIA modems as well  as  GPRS
47       and 3G datacards.
48
49       comgt has some features that are rarely found in other utilities of the
50       same type.
51
52   Features
53       - Pre-defined built-in scripts for 2G/3G datacard control
54       - Simple, BASIC-like script language.
55       - Command-line and file sourcing of script.
56       - Multi-response waitfor.
57       - waitquiet permits line stabilization.
58       - In-line text capture.
59       - Multi-process support: fork, wait, kill, exit.
60       - Debugging verbose and log output.
61       - logging to file.
62       - Flow control: goto, gosub, return, if, else.
63       - Low-impact on system resources.
64       - Time commands and functions.
65       - String manipulations.
66       - Environment manipulation: env(), putenv.
67       - External utilities system calls: system, exec.
68
69   Supported GPRS and 3G datacards
70       comgt has been tested against GlobeTrotter GPRS,EDGE, Combo  EDGE,  3G,
71       3G  EDGE, HSDPA and GlobeTrotter Fusion as well as Vodafone 3G.  It can
72       set the PIN and display information about datacards before a  PPP  con‐
73       nection  is  started.  Additionally, because the GlobeTrotter and Voda‐
74       fone 3G/GPRS datacard have a secondary serial interface,  these  datac‐
75       ards can be monitored while a PPP connection is in existence and trans‐
76       ferring data.
77
78       comgt is primarily designed to work with the GlobeTrotter range of dat‐
79       acards but should be compatible with any other GPRS or 3G datacard pro‐
80       vided its interface is implemented as one or more serial or USB  serial
81       devices  and  it  is controlled and queried by an implementation of the
82       Hayes command interface with the same AT command extensions used by the
83       listed datacards.
84
85   Using comgt
86       comgt has only one function: to run a script. This may be one of a num‐
87       ber of "standard" internal scripts or an external script. Both types of
88       script  are  invoked  in the same way. The "standard" scripts are built
89       into comgt and  will  work  for  serially  connected  modems,  built-in
90       modems, PCMCIA modems as well as the GlobeTrotter GPRS and the Vodafone
91       3G/GPRS datacards.  There is a search  priority  order  for  scripts  -
92       1)internal, 2)working directory, 3)/etc/comgt
93
94   Built-in scripts
95  comgt
96       This runs the default internal script. Running comgt without any script
97       specified, e.g., comgt -d /dev/ttyS1 it will check for a PIN and prompt
98       you if it is required. The next thing it does is wait for the device to
99       register, it then reports the signal strength.  If you don´t specify  a
100       port  with  the -d option then /dev/modem is assumed.  If the -s switch
101       is not used then this default script is run before any external script.
102
103  comgt help
104       Lists these and the other options available.
105
106  comgt info
107       Lists the datacard configuration.
108
109  comgt sig
110       Prints the signal strength.
111
112  comgt reg
113       Prints the registration state.
114
115  comgt 3G
116       Puts a GlobeTrotter 3G/Fusion and Vodafone 3G into 3G network only mode
117       (UMTS/HSDPA).
118
119  comgt 2G
120       Puts a GlobeTrotter 3G/Fusion and Vodafone 3G into 2G network only mode
121       (GSM/GPRS/EDGE).
122
123  comgt 3G2G
124       Puts a GlobeTrotter 3G/Fusion and Vodafone 3G into  3G  preferred  mode
125       (UMTS/HSDPA and GSM/GPRS/EDGE).
126
127  comgt GTEDGE
128       Use this command to initialise GlobeTrotter EDGE and GlobeTrotter Combo
129       EDGE cards before doing anything else. (It switches on the radio).
130
131  comgt USA
132       Switch to 900/1900 MHz band for USA operation. GlobeTrotter GPRS datac‐
133       ards only.
134
135  comgt EUROPE
136       Switch  to  900/1800 MHz band for European operation. GlobeTrotter GPRS
137       datacards only.
138
139  comgt PIN
140       Test the SIM PIN status and use the environment  variable  COMGTPIN  as
141       the value .
142
143  comgt APN
144       Set  the  APN  of  the  datacard to the value contained in the COMGTAPN
145       environment variable.
146
147
148   Custom Scripts
149       As well as built in scripts you can make your own. The following script
150       sets a Vodafone 3G datacard or Option Fusion card´s UMTS mode to GPRS:
151
152            #Set GPRS only mode
153            set com 115200n81
154            set senddelay 0.05
155            waitquiet 1 0.2
156            send "AT_OPSYS=0^m"
157            print "Setting GPRS only mode"
158
159       If you saved the above script as GPRS you would call it like this:
160
161            comgt GPRS
162
163       If you needed to specify the port as well then do this:
164
165            comgt -d /dev/ttyS1 GPRS
166
167       You can also pass environment parameters to a comgt script via $env().
168
169
170   Replacing chat
171       chat  is  a utility that comes with the ppp package (for Linux, anyway)
172       that, with a set of expect-send string couples, does enough to  connect
173       most  people  to  ISPs  and  such.  While chat´s use is very simple, it
174       isn´t very flexible.  That´s where comgt takes over.
175
176       comgt can be used in place of chat using the same strategy.  For  exam‐
177       ple, a pppd line reading:
178
179            pppd connect \
180                 ´chat -v "" ATDT5551212 CONNECT "" ogin: ppp \
181                 word: whitewater´ \
182                 /dev/cua1 38400 debug crtscts modem defaultroute
183
184       Would, using comgt, read:
185
186            pppd connect ´comgt -s /root/scripts/isp.scr´ /dev/cua1 38400 \
187                 debug crtscts modem defaultroute
188
189       And the isp.scr script would read:
190
191            send "ATDT5551212^m"
192            waitfor 60 "ogin:"
193            send "ppp^m"
194            waitfor 60 "word:"
195            send "whitewater^m"
196
197       Of  course it then becomes trivial to make this script a whole lot more
198       functional by adding code for busy detect, re-dialing, etc...
199
200   Verbose output
201       When the verbose option is turned on, comgt reports  everthing  on  the
202       standard  error  channel.  If turned on from the command line (-v), the
203       output contains 4 sections.
204
205       - Command line argument actions
206         These are actions taken because they were specified from the  command
207         line,  such as opening a communication device (-d), etc...  For these
208         to be output, you must specify -v as the first argument.
209
210       - List of arguments
211         The number and list of arguments passed. This is useful in  case  you
212         have  a  bunch of environment variables or quotes, back-quotes, back‐
213         slashes on the command line and  you´re  not  sure  what  the  script
214         really sees.
215
216       - Script list
217         A  list of the script to execute.  This may be a concatenation of the
218         default internal script, unless this is suppressed by the -s  option,
219         and  a  script  file.   Every line is listed with its line number and
220         character position.
221
222       - Execution output
223         List of commands as they are executed. The parser prints the line its
224         currently  on,  starting from the exact point where its at to the end
225         of the line. Multiple command groups on a single line produce  multi‐
226         ple  output  lines.  Verbose  output  may be mixed with script output
227         (print, eprint or lprint.)
228
229       Here´s an example:
230
231         $ comgt -v -d/dev/cua1 -s blah.scr
232         comgt 00:18:46 -> Verbose output enabled
233         comgt 00:18:46 -> Script file: blah.scr
234         comgt 00:18:46 -> argc:5
235         comgt 00:18:46 -> argv[0]=comgt
236         comgt 00:18:46 -> argv[1]=-v
237         comgt 00:18:46 -> argv[2]=-d/dev/cua1
238         comgt 00:18:46 -> argv[3]=-s
239         comgt 00:18:46 -> argv[4]=blah.scr
240         comgt 00:18:46 ->  ---Script---
241            1@0000 set com 38400n81 let a=2
242            2@0025 print "9x",a,"=",9*a,"\n"
243            3@0051 sleep 5
244            4@0059 exit 0
245         comgt 00:18:46 ->  ---End of script---
246         comgt 00:18:46 -> @0000 set com 38400n81 let a=2
247         comgt 00:18:46 -> @0017 let a=2
248         comgt 00:18:46 -> @0025 print "9x",a,"=",9*a,"\n"
249         9x2=18
250         comgt 00:18:46 -> @0051 sleep 5
251         comgt 00:18:51 -> @0059 exit 0
252

Programming manual

254   Syntax
255       The syntax used for comgt scripts is  rather  simple,  somewhat  BASIC-
256       like.   A  script  is  a non-tokenized, pure ASCII text file containing
257       lines terminated by newline characters (Unix standard.)  Scripts can be
258       created  and/or  modified using any standard text editor (vi, vim, joe,
259       pico, emacs, ed, microEmacs) Lines in a comgt script read like so:
260
261        - Empty line
262        - [indent]rem remark
263        - [indent][[:|label] LABEL] [command [arguments]] rem remark
264        - [indent][[:|label] LABEL] [command [arguments]] [command [arguments]]...
265
266       Characters used for indentation are the space and tabulation characters.
267       The rem command makes the script parser skip the rest of the line.
268       The rem command can also be written as "#" or "//".
269
270       Labels consist of lowercase and uppercase letters and digits.
271       Case is ignored in labels.
272
273       Commands and their arguments are separated by spaces and/or tabs.
274       Command groups are separated by spaces, tabs, or newlines.
275
276       Expressions must not contain spaces or tabs.
277       This is ok : let n=x+76
278       This is not: let n= x + 76
279         Because this space ^ would terminate the let command group.
280
281   Error reporting
282       When comgt detects a script error,  it  immediately  turns  on  verbose
283       mode,  generates  a  dump  (see the dump command), reports the error in
284       three lines and stops the execution.  The first line  reported  is  the
285       command group being executed, the second one shows where the parser got
286       and the third line  reports  the  character  position  of  the  program
287       counter, the error and the exit code.
288
289       Here´s an example:
290
291            $ comgt -vs blar2.scr
292
293       Where the blar2.scr script is:
294
295            inc n
296            dec d3
297            let a=58/3
298            let $d="fod"
299            let c=1/0
300            let $y4="sdfgsdfgsdfg"
301
302       The trace and error report looks like this:
303
304            comgt 11:20:15 -> Verbose output enabled
305            comgt 11:20:15 -> Script file: blar2.scr
306            comgt 11:20:15 -> argc:3
307            comgt 11:20:15 -> argv[0]=comgt
308            comgt 11:20:15 -> argv[1]=-vs
309            comgt 11:20:15 -> argv[2]=blar2.scr
310            comgt 11:20:15 ->  ---Script---
311               1@0000 inc n
312               2@0007 dec d3
313               3@0015 let a=58/3
314               4@0027 let $d="fod"
315               5@0041 let c=1/0
316               6@0052 let $y4="sdfgsdfgsdfg"
317            comgt 11:20:15 ->  ---End of script---
318            comgt 11:20:15 -> @0000 inc n
319            comgt 11:20:15 -> @0007 dec d3
320            comgt 11:20:15 -> @0015 let a=58/3
321            comgt 11:20:15 -> @0027 let $d="fod"
322            comgt 11:20:15 -> @0041 let c=1/0
323            comgt 11:20:15 -> -- Error Report --
324            comgt 11:20:15 -> ---->         ^
325            comgt 11:20:15 -> Error @49, line 5, Division by zero. (6)
326
327   Exit codes
328       When  comgt terminates, it does so with an "exit code".  That is a num‐
329       ber passed back to the calling process to signify success or  failures.
330       In  every-day  Unix,  0  (zero) means success and everything else means
331       whatever the author of the program  wants  it  to  mean.   In  a  shell
332       script, or directly on the command line, you may look at the content of
333       $?  after having called comgt to examine its exit code.
334
335       Example:
336
337            #!/bin/sh
338            comgt /root/bin/call-isp
339            if [ $? != 0 ]; then
340              echo "Oops! Something went wrong."
341            fi
342
343       Internal comgt error codes are as follows:
344
345            0 : No problems whatsoever.  Apparently.
346            1 : Communication device problems.
347            2 : Console (tty) device problems.
348            3 : Memory problems.
349            4 : File or pipe problems.
350            5 : Syntax errors.
351            6 : Division by zero.
352            7 : Variable mis-management.
353            8 : System problems.  (Couldn´t call /bin/sh or some such)
354
355   Commands
356       Command     : :   Alias: label
357       Description : Notes an anchor point for goto or gosub to branch to.
358       Syntax      : Keyword must not contain any special characters.
359       Note        : Must be first statement in a line.
360       See Also    : goto, gosub, return.
361       Example:
362                     :loop
363                     gosub bravo
364                     print "The time is ",$time(),"\n"
365                     sleep 1
366                     goto loop
367                     label bravo
368                     print "Twonk!\n"
369                     return
370
371       Command     : abort
372       Description : Causes comgt to call abort() and produce a core dump.
373       Syntax      : abort
374       See Also    : dump, exit.
375
376
377       Command     : cd
378       Description : Change directory.
379       Syntax      : cd directory
380       Notes       : -1 is returned in % if the change could not be made.
381       Notes       : directory is a string and thus could be a variable.
382       See Also    : $cwd().
383       Example:
384                     cd "duh"
385                     if % != 0 print "Could not cd into duh.\n"
386
387
388       Command     : close
389       Description : closes file previously opened with open.
390       Syntax      : close file
391       See Also    : open.
392
393
394       Command     : dec
395       Description : Decrements the content of an integer variable by 1.
396       Syntax      : dec x
397       Notes       : x is from a to z or a0 to z9.
398       Notes       : Note that "let x=x-1" also works.
399       See Also    : let, inc.
400
401
402       Command     : dump
403       Description : Lists all non-zero integer variables and modified string
404       Description : variables as log entries (standard error channel.)
405       Syntax      : dump
406       See Also    : abort, exit
407
408
409       Command     : else
410       Description : Alternatively execute commands if last "if" tested false.
411       Syntax      : else commands...
412       See Also    : if
413       Example:
414                     if w<350 print "Wow! Imagine that.\n"
415                     else print "Rush Limbaugh is a big fat bastard.\n"
416
417
418       Command     : eprint
419       Description : print a comma-separated list of arguments on stderr.
420       Syntax      : eprint var,stringvar,"text",...
421       Notes       : Like print but on the standard error file descriptor.
422       Notes       : The error output can be re-directed with "2>file" on
423       Notes       : the command line.
424       See Also    : print.
425
426
427       Command     : exec
428       Description : Replaces current comgt process with another process.
429       Syntax      : exec "command -args..."
430       See Also    : system, fork.
431       Example:
432                     #Finished script, call cu.
433                     exec "cu -l "+$dev()+" -s "+$baud()
434
435
436       Command     : exit
437       Description : terminates script execution with exit code.
438       Syntax      : exit exit_code
439       See Also    : abort, dump.
440       Example:
441                     :error
442                     exit 1
443                     :smeggit
444                     exit 0
445
446
447       Command     : flash
448       Description : Toggles DTR on communication device for a specified time.
449       Syntax      : flash float_constant
450       Notes       : float_constant is precise down to 1/100th sec.
451       Notes       : Causes modem to drop carrier or go to command mode,
452       Notes       : depending on modem settings.  Setting the baud rate to 0
453       Notes       : for a time has the same effect.
454       See Also    : sleep, set com.
455       Example:
456                     :disconnect
457                     flash 0.5
458                     exit 0
459
460
461       Command     : fprint
462       Description : print a comma-separated list of arguments in a file.
463       Syntax      : fprint var,stringvar,"text",...
464       Notes       : Like print but appended to a file previously opened
465       Notes       : by open.
466       See Also    : print.
467
468
469       Command     : fork
470       Description : forks comgt process in two.  Both processes continue
471       Description : executing the script.
472       Syntax      : fork
473       Notes       : % returns 0 for child process, new process ID for
474       Notes       : parent or -1 for error.
475       See Also    : wait, kill, pid(), ppid().
476       Example:
477                     fork
478                     if % = -1 goto error
479                     if % = 0 goto child
480                     :parent
481                     ...
482
483       Command     : get
484       Description : get string from communication device.
485       Syntax      : get timeout "terminators" $string
486       Notes       : timeout is a float constant, terminators is a
487       Notes       : list of characters that, when received, terminate
488       Notes       : get.  Terminators are ignored when received first.
489       See Also    : waitfor.
490       Example:
491                     waitfor 60 "connect"
492                     if % != 0 goto error
493                     get 2 " ^m" $s
494                     print "Connection parameters: ",$s,"\n"
495
496
497       Command     : gosub
498       Description : calls a subroutine.
499       Syntax      : gosub label
500       Notes       : Currently, comgt only supports 128 levels of gosub
501       Notes       : calls (enough!)
502       See Also    : :, goto, return.
503       Example:
504                     gosub routine
505                     sleep 1
506                     gosub routine
507                     goto end
508                     :routine
509                     print "Flim-flam!\n"
510                     return
511
512
513       Command     : goto
514       Description : Sends execution somewhere else in the script.
515       Syntax      : goto label
516       See Also    : :, gosub, return.
517       Example:
518                     :win95
519                     print "Today I want to go and use Linux, thank you.\n"
520                     goto win95
521
522
523       Command     : hset
524       Description : Set the hundreds timer.
525       Syntax      : hset value
526       Notes       : This command resets the hundreds of seconds timer to
527       Notes       : a value for htime to start from.
528       See Also    : htime().
529       Example:
530                     hset 0
531                     :loop
532                     print "Time in 1/100 of a sec.: ",htime(),"\n"
533                     sleep 0.01
534                     goto loop
535
536
537       Command     : if
538       Description : tests a condition
539       Syntax      : if test_condition commands...
540       Notes       : Conditionnaly executes commands if test condition is true.
541       Notes       : Test operators are = (equal), != (not equal),
542       Notes       : <> (not equal to) < (less than), > (greater than),
543       Notes       : <= (less or equal), >= (greater or equal).
544       Notes       : All operators can be used with integers and strings.
545       Notes       : If test_condition is false, if skips to
546       Notes       : the next line.
547       See Also    : else.
548       Example:
549                     if n>30 print "Oh-ho! too many sheep!\n" goto error
550                     if n=17 print "Hurray! we´ve enough sheep\n" goto party
551                     if n<17 print "Murray, get more sheep.\n" goto getmore
552                     if $z < "Marmaluke" goto ...
553                     if 3*a>5+b goto ...
554
555
556       Command     : inc
557       Description : increments the content of an integer variable by 1.
558       Syntax      : inc x
559       Notes       : x is a-z or a0-z9.
560       See Also    : dec, let.
561
562
563       Command     : input
564       Description : input string from keyboard into string variable.
565       Syntax      : input $x
566       Notes       : input terminates entry only with the ENTER key.
567       Notes       : Spaces, tabs and other funny characters are all
568       Notes       : stored in the variable.
569       See Also    : set echo.
570       Example:
571                     print "Enter your full name :"
572                     input $n4
573
574
575       Command     : kill
576       Description : Sends a signal to a process.
577       Syntax      : kill signal processID
578       Notes       : Both signal and processID are integer values.  Same as
579       Notes       : standard unix kill except that signal aliases are not
580       Notes       : accepted and signal is not optional.
581       Notes       : 0 is returned in % if the signal could be sent, -1
582       Notes       : otherwise.
583       Notes       : Signal 0 can be used to detect process existance.
584       See Also    : wait, pid(), ppid().
585       Example:
586                     fork
587                     let p=%
588                     if p = 0 goto child
589                     sleep 300
590                     kill 15 p
591                     sleep 1
592                     kill 0 p
593                     if % != 0 print "Child terminated\n" goto ok
594                     print "Could not terminate child!\n"
595                     kill 9 p
596                     sleep 1
597                     kill 0 p
598                     if % = 0 print "Could not kill child!\n" goto error
599                     print "Child killed.\n"
600                     :ok
601                     ...
602
603
604       Command     : let
605       Description : Does a variable assignment.
606       Syntax      : let x=content
607       Notes       : x is [$]a0-z9.
608       See Also    : inc, dec.
609       Example:
610                     let a=5
611                     let b=(time()-a)+5
612                     let y7=6809
613                     let z=0%11010111  #Binary
614                     let z=077324      #octal
615                     let z=0xf5b8      #hexadecimal
616                     let $c="Daniel "
617                     let $d=$c+" Chouinard"
618                     let $s5="Frimpin´ Jeosaphat!"
619
620
621       Command     : lprint
622       Description : Print a comma-separated list of arguments to the log.
623       Syntax      : fprint var,stringvar,"text",...
624       Notes       : Like print but printed like a log entry if verbose is on.
625       Notes       : logging is sent to stderr.
626       See Also    : print, eprint, fprint.
627
628
629       Command     : open
630       Description : Opens a file or a communication device.
631       Syntax      : open com device, open com (stdin), open file FILE
632       See Also    : close.
633       Example:
634                     open com /dev/cua1
635                     set com 38400n81
636                     open file "/tmp/log"
637                     fprintf "This is a log\n"
638                     close file
639
640
641       Command     : print
642       Description : print a comma-separated list of arguments.
643       Syntax      : print var,stringvar,"text",...
644       Notes       : Spaces and newlines are not automatically added.
645       See Also    : eprint, fprint, lprint.
646       Example:
647                     let b=26
648                     let $c="text variables"
649                     print "Contstant text ",b," ",$c," time: ",$time(),"\n"
650
651
652       Command     : putenv
653       Description : Sets an environment variable.
654       Syntax      : putenv "var=content"
655       Notes       : Environment variables are automatically exported,
656       Notes       : never returned. Children processes inherit the
657       Notes       : environment.
658       See Also    : $env().
659       Example:
660                     putenv "SCRIPTDIR=/usr/lib/comgt/scripts"
661                     system "dothat"  # dothat reads env. var. SCRIPTDIR...
662
663
664       Command     : rem  Aliases: #, //
665       Description : Remark.  Rest of line is ignored.
666       Syntax      : Note that a space must follow "rem".
667       Example:
668                     #This is a remark
669                     // So is this
670                     rem This ain´t no disco.
671
672
673       Command     : return
674       Description : Returns from subroutine.
675       Syntax      : return
676       See Also    : gosub.
677
678
679       Command     : send
680       Description : sends a string to the communication line (modem usually).
681       Syntax      : send string
682       Notes       : Carriage return (ENTER) is not sent automatically
683       Notes       : (use ^m).
684       Example:
685                     send "atdt555-1212^m"
686                     send $g+"^m"
687                     send "The time is "+$time()+"^m^j"
688
689
690       Command     : set
691       Description : sets working parameters.
692       Syntax      : set parameter value
693       Notes       :
694
695       Command                       Description
696       ----------------------------- -------------------------------------------------
697       set echo on|off               Keyboard echo on-screen.
698       set comecho on|off            Received characters echoed on-screen.
699       set senddelay time_constant   In-between character delay for "send"
700       set ignorecase on|off         Case sensitivity for "waitfor".
701                                     Default=on.
702       set clocal on|off             clocal on = ignore modem signals
703       set umask mode                file mode creation defaults.
704                                     See man umask.
705       set verbose on|off            verbose on = debug output enabled.
706       set com com_params            communication parameters.
707                                          ex.: 19200n81, 300e71
708                                                    baud |||
709                                                  Parity    |
710                                               Data bits     |
711                                               Stop bits      |
712
713       Example:
714                     set echo off
715                     print "Password :"
716                     input $p
717                     print "\n"
718                     set echo on
719                     set comecho on
720                     set clocal on
721                     set senddelay 0.1
722                     set ignorecase on
723                     set com 38400n81
724                     set umask 022 # Must be octal (leading zero)
725                     ...
726
727       Note on clocal:
728         If want your script to keep working after the carrier detect
729         signal has dropped, set clocal on, otherwise, a CD drop causes
730         the device line to close (hang up).  This could happen if,
731         let´s say, your script calls and connects, then disconnects or
732         drops dtr (flash), then tries to re-connect again.
733
734
735       Command     : sleep
736       Description : Pauses execution.
737       Syntax      : sleep float_constant
738       Notes       : Float_constant is precise down to 1/100th sec, unless
739       Notes       : more than 100 seconds, in which case the precision
740       Notes       : falls down to 1 sec.
741
742       Example:
743                     sleep 0.06
744                     sleep 3
745                     sleep 86400 /* A whole day */
746
747
748       Command     : system
749       Description : Calls a system (unix) command
750       Syntax      : system "command"
751       See Also    : exec.
752       Example:
753                     :dir
754                     print "listing of directory ",$cwd(),\n"
755                     system "ls -l |more"
756
757
758       Command     : testkey
759       Description : Tests keyboard for keystroke, returns 1 in % if present.
760       Syntax      : testkey
761       Notes       : Can only test for ENTER key.  Future versions of comgt
762       Notes       : will test for more and return keycodes in %.
763       See Also    : input.
764       Example:
765                     let n=1
766                     :loop
767                     print n," sheep... ZZZzzz...\n"
768                     sleep n
769                     inc n
770                     testkey
771                     if % = 0 goto loop
772
773
774       Command     : wait
775       Description : Wait for a child process to terminate.
776       Syntax      : wait
777       Notes       : Process ID of terminated child is returned in %
778       See Also    : fork, kill.
779       Example:
780                     fork
781                     let p=%
782                     if p=0 goto child
783                     if p=-1 goto error
784                     print "Waiting for child to finish..."
785                     wait
786                     print "\n"
787                     if %!=p print "Wait got wrong PID!\n" goto error
788                     print "Child is done.\n"
789
790
791       Command     : waitfor
792       Description : Waits until one of a list of strings is received
793       Syntax      : waitfor timeout "string1","string2","string3"...
794       Notes       : Timeout is a floating time constant.  waitquiet returns
795       Notes       : 0 for the first string received, 1 for the second, etc...
796       Notes       : and -1 for a timeout.  Case is ignored by default unless
797       Notes       : ignorecase is set to off.
798       See Also    : get.
799       Example:
800                     :dial
801                     send "atdt555-4411^m"
802                     waitfor 60 "no carrier","busy","no dial tone","connect"
803                     if % = -1 goto timedout
804                     if % = 0 goto nocd
805                     if % = 1 goto redial
806                     if % = 2 goto error
807                     if % = 3 goto connected
808
809
810       Command     : waitquiet
811       Description : Waits until communication line stops receiving for a time.
812       Syntax      : waitquiet timeout quiettime
813       Notes       : Both timeout and quiettime are floating time constants
814       Notes       : with 1/100th sec. accuracy.  Usefull for "swallowing"
815       Notes       : incoming characters for a while or waiting for an
816       Notes       : unknown prompt.
817       Example:
818                     :closecon
819                     send "logoff^m"
820                     waitquiet 10 0.5
821                     send "yes^m"
822
823   Integer functions
824       I-Function  : Access
825       Description : Verifies access rights to a file
826       Syntax      : let x=access("/tmp/file","frwx")
827       Notes       : The second string contains one or more of
828       Notes       : ´f´,´r´,´w´,´x´ to repectively check
829       Notes       : existence, read, write and execute permissions.
830       Notes       : Under root id, the only useful check is ´f´, as
831       Notes       : all others will return true.
832       Return Value: 0 if the file exists, is readable, writable,
833       Return Value: executable, or -1 if not.
834       See Also    : man access(2)
835
836       I-Function  : baud
837       Description : Returns current baudrate of communication line.
838       Syntax      : let x=baud()
839       Notes       : Does not necessarily match the modem connection speed.
840       See Also    : $baud().
841
842       I-Function  : len
843       Description : Returns the length of a string.
844       Syntax      : let x=len($s)
845       Notes       : "" is zero.  Strings currently have a maximum length of
846       Notes       : 1024 characters. comgt doesn´t handle string overflow
847       Notes       : at all.
848
849       I-Function  : htime
850       Description : Returns hundreds of seconds since start of script.
851       Syntax      : let x=htime()
852       Notes       : Set to a specific value with hset.
853       See Also    : hset.
854
855       I-Function  : pid
856       Description : Returns process ID number of current process (comgt)
857       Syntax      : let x=pid()
858       See Also    : ppid(), fork
859
860       I-Function  : ppid
861       Description : Returns process ID number of parent process.
862       Syntax      : let x=ppid()
863       Notes       : Can be used by forked child to detect parent
864       Notes       : process.
865
866       I-Function  : time
867       Description : Returns time in seconds since Jan 1, 00:00:00 1970 GMT.
868       Syntax      : let x=time()
869       Notes       : Used to calculate time differences.
870       See Also    : $time()
871
872
873       I-Function  : val
874       Description : Returns value of string.
875       Syntax      : let x=val($x)
876       Notes       : String is not an expression; must only contain [0-9]
877       Notes       : characters. Future versions of comgt will be able to
878       Notes       : evaluate expressions. (Maybe) (This was written 6
879       Notes       : years ago.)
880
881
882       I-Function  : verbose
883       Description : Returns value of verbose setting.
884       Syntax      : let x=verbose()
885       Notes       : 0=off, 1=on.
886
887   String functions
888       S-Function  : basename
889       Description : Returns basename part of path.
890       Syntax      : let $x=$basename($p)
891       Notes       : $basename("/usr/bin/more")="more"
892       See Also    : $dirname().
893
894       S-Function  : baud
895       Description : Returns string representation of current baud rate.
896       Syntax      : let $x=$baud()
897       Notes       : Defined by "set com"
898       See Also    : baud(), set com.
899
900       S-Function  : cwd
901       Description : Returns current working directory pathname.
902       Syntax      : let $x=$cwd()
903       See Also    : cd.
904
905       S-Function  : dev
906       Description : Returns current communication device pathname.
907       Syntax      : let $x=$dev()
908       Notes       : defined by "-d" command line argument or "open com"
909       See Also    : open com.
910
911       S-Function  : dirname
912       Description : Returns directory name part of path.
913       Syntax      : let $x=$dirname($p)
914       Notes       : $dirname("/usr/bin/more")="/usr/bin"
915       See Also    : $basename().
916
917       S-Function  : env
918       Description : Returns content of an environment variable
919       Syntax      : let $x=$env("HOME")
920       Notes       : Non-existant variables return an empty string.
921       See Also    : putenv.
922
923       S-Function  : hex
924       Description : Converts value to hexadecimal representation
925       Syntax      : let $x=$hex(x)
926       Notes       : Letters a-f in lowercase, no preceding "0x"
927       See Also    : $hexu(), $oct().
928
929       S-Function  : hexu
930       Description : Converts value to hexadecimal representation
931       Syntax      : let $x=$hex(x)
932       Notes       : Letters A-F in uppercase, no preceding "0x"
933       See Also    : $hex(), $oct().
934
935       S-Function  : hms
936       Description : Converts number of seconds into time string
937       Syntax      : let $x=$hms(x)
938       Notes       : Format is "HH:MM:SS".  Useful for chronometer displays
939       Notes       : Use with "time()", do not try to increment a variable
940       Notes       : every second using "sleep 1".  (See ISP script example)
941       Notes       : Format becomes "HHH:MM:SS" after 99 hours, 59 minutes,
942       Notes       : 59s...
943       See Also    : time().
944
945       S-Function  : left
946       Description : Returns left portion of a string
947       Syntax      : let $x=$left($s,l)
948       Notes       : $s=Source string, l=length
949       Notes       : l must be less than the length of the string.
950       See Also    : $right(), $mid().
951
952       S-Function  : mid
953       Description : Returns midsection of a string.
954       Syntax      : let $x=$mid($s,s,l)
955       Notes       : $s=Source string, s=start, l=length
956       Notes       : s must be less than the length of the string, l can be
957       Notes       : some huge number (9999) to return the right side of a
958       Notes       : string to the end.  the first character of a string is
959       Notes       : position 0, not 1.
960       See Also    : $right(), $left().
961
962       S-Function  : oct
963       Description : Converts value to octal representation.
964       Syntax      : let $x=$oct(x)
965       See Also    : $hex(), $hexu().
966
967       S-Function  : right
968       Description : Returns right portion of a string.
969       Syntax      : let $x=$right($s,l)
970       Notes       : $s=Source string, l=length
971       Notes       : l must be less than the length of the string.
972       See Also    : $left(), $mid().
973
974       S-Function  : rpipe
975       Description : Returns the first line from a system piped command
976       Syntax      : let $x=$rpipe("/bin/ls |grep myfile")
977       Notes       : Not very useful unless used with head, tail, grep,
978       Notes       : etc...
979       See Also    : system.
980
981       S-Function  : time
982       Description : Returns 24 character local time string
983       Syntax      : let $x=$time()
984       See Also    : time().
985       Notes       : Time is in this format: Mon Apr  8 14:21:22 1996
986                                             012345678901234567890123
987                                                       1         2
988
989       S-Function  : tolower
990       Description : Returns lowercase´d string.
991       Syntax      : let $x=$tolower($y)
992
993       S-Function  : toupper
994       Description : Returns uppercase´d string.
995       Syntax      : let $x=$toupper($y)
996
997   Test operators
998       Operator Description       Example       Result
999       =        equal             if 1+2=3      yes
1000       !=       not equal         if 1+2!=3     no
1001       <>       not equal         if 1+2<>3     no
1002       >        Greater than      if 1+3>3      yes
1003       <        Less than         if 1+3<3      no
1004       >=       Greater or equal  if 3>=3       yes
1005       <=       Greater or equal  if 2<=3       yes
1006
1007       Strings can be compared using the same operators.
1008
1009       "aaa" < "aab",  "aaaa" > "aaa", "Test" != "test", "One" = "One",
1010       "A" > "a", "Fumble" <= "Fumigate", "Farsical" <> "Comedic"
1011
1012       Note that "set ignorecase on" does NOT apply to string comparisons.
1013
1014   Expression operators
1015       Operator  Description      Example           Result
1016       +         Addition         let a=2+2         4
1017       +         Concatenation    let $b="aa"+"bb"  "aabb"
1018       -         Substraction     let e=2-5         -3
1019       *         Multiplication   let f=11*2        22
1020       /         Division         let g=34/11       3
1021       &         Bit-Wise AND     let h=42&7        2
1022       |         Bit-Wise OR      let a=42|5        47
1023       ^         Bit-Wise XOR     let a=42^7        45
1024
1025       Mixed expression examples:
1026
1027       #Returns number of seconds since 00:00:00
1028       let $t=$time() #Take a snapshot.
1029       let a=(val(mid$($t,11,2))*3600)+(val(mid$($t,14,2))*60)+val(mid$($t,17,2))
1030       #Notice the extra sets of parenthesis because comgt´s expression
1031       #evaluator is brain-dead.
1032       #For example, 5-2+1 should give you 4, right?  Well, according to
1033       #getvalue(), it actually gives 2, because it does it somewhat from
1034       #right to left.
1035       #So to evaluate 5-2+1 correctly, use (5-2)+1.  If you´re using
1036       #simple, two-element calculations, don´t worry about it.
1037       #5-2 will give you 3.
1038
1039       #Concatenation  (Calls cu)
1040       exec "cu -l "+$dev()+" -s "+$baud()"
1041
1042       #In a test condition
1043       if a+c > strlen($c) goto toomuch
1044
1045       #String comparison
1046       let $t=$mid($time(),11,8)
1047       if $t > "19:59:59" print "Too late for that!\n" goto toolate
1048       if $t < "08:00:00" print "Too early!\n" goto tooearly
1049       if $t = "00:00:00" print "Oh god!  It´s Twinkee time!\n"
1050

KNOWN FEATURES

1052       The getvalue() parser.  It makes me laugh so I think I´ll leave it that
1053       way.  - Daniel.Chouinard@pwc.utc.com
1054

ENVIRONMENT VARIABLES

1056       COMGTPIN  - the 4 digit pin of the SIM for use by PIN script COMGTAPN -
1057       the APN to write to the data card, used by the APN script.
1058

AUTHORS

1060       Daniel.Chouinard <Daniel.Chouinard@pwc.utc.com> wrote the original dcon
1061       utility.
1062
1063       Paul  Hardwick  <paul@peck.org.uk> updated it for the latest compilers,
1064       provided the built-in script functionality and tested it  against  GPRS
1065       and 3G datacards.
1066
1067       Martin  Gregorie  <martin@gregorie.org>  wrote the original manpage for
1068       comgt from the dcon documentation and packaged comgt for distribution.
1069
1070   History
1071       Daniel Chouinard wrote most (90%) of dcon back in 1989 when he  started
1072       doing  Unix  Apps tech support mostly by modem to customer systems.  He
1073       was tired of typing all those passwords and funny  call-charging  codes
1074       everytime  he used cu.  Also, the company he worked for needed a system
1075       that would log call times and estimated costs.   Thus  dcon  was  born.
1076       Six or seven years later (1996) and he was using pppd to connect to his
1077       ISP site.  He was more or less happy with chat but found it lacked flow
1078       control  and  multiple response checks from "atdt...".  He wanted it to
1079       do different things for "no  carrier",  "no  dial  tone",  and  "busy".
1080       Although  he thought that chat would probably be enhanced someday, when
1081       he found dcon.c on one of his old 45M tapes he tried  compiling  it  on
1082       his  Linux  box and, lo and behold, it did.  In the end, he added a few
1083       things to it (kill, fork, wait, 1/100 sec. times) and left it at that.
1084
1085       A couple of years ago Paul Hardwick found the program, dcon 0.97,  last
1086       modified  in  1996. The purpose of this program was to run scripts that
1087       would control Linux serial ports. The implementation was  very  similar
1088       to  something  he had written for Windows. Anyway, rather than reinvent
1089       he contacted the author, Daniel Chouinard, and asked his permission  to
1090       reuse  the  code.   Happily  he  gave permission and a basic but useful
1091       utility called comgt was created. Paul takes no credit for the  engine,
1092       apart from making it compatible with todays compilers.  It is basically
1093       dcon repackaged.
1094
1095
1096
1097
1098
1099                               20 October, 2006                       comgt(1)
Impressum