# Falls Sie eine Website erwarten, aber diesen # Abschnitt lesen können, löschen Sie bitte das # _index.htmx_comgt # vom Ende der Adresszeile. Danke! Lang: de Title: comgt: Neue Version 0.42g Short Title: comgt Publication date: 2020-10-03 Meta: en Title: comgt: New version 0.42g Short Title: comgt +INFO +Download +Beispiel +MAN >>INFO de 1.0
Ersonnen/programmiert von Daniel Chouinard, Paul Hardwick und Martin Gregorie.
Ergänzt von Jonas Bechtel.
Eine interaktive Skripteingabe ist noch nicht möglich. (Dafür aber Konsoleninteraktionen mit dem ausgeführten Skript)
Zur Nutzung mit einem Skript: comgt -s [scriptdatei.comgt]
aufrufen,
z. B. nach dem Kompiliervorgang mit installiertem nc und socat
./comgt -s test/test.comgt
Devised/implemented by Daniel Chouinard, Paul Hardwick and Martin Gregorie.
Supplemented by Jonas Bechtel
An interactive script input is not yet possible. (But console interactions with executed scripts)
To use with a script file invoke comgt -s [scriptfile.comgt]
, e. g.
after compiling with nc and socat installed ./comgt -s test/test.comgt
Lots of improvements/refactoring/compatibility (including $version and $versionnumber tokens and v3r special variable)
Using newest bstring package: 2021b with git without git
comgt-0.42g-src.tgz -> uncompressed comgt-0.42g-src.tar
comgt-0.42g-armv7l (right-click, save-as // Rechtsklick, Speichern als)
(GNU/Linux embedded)
comgt-0.42g-x86_64_newlibc
(right-click, save-as // Rechtsklick, Speichern als)
(GNU/Linux, new computers, 64bit, only works on 64bit)
comgt-0.42g-x86_oldlibc
(right-click, save-as // Rechtsklick, Speichern als)
(MOST PORTABLE: GNU/Linux, old and new computers, 32bit, usually also works on 64bit)
comgt-0.42g-x86_newlibc
(right-click, save-as // Rechtsklick, Speichern als)
(GNU/Linux, new computers, 32bit, usually also works on 64bit)
$ du -shx bstring2021b* comgt-0.42g-{g,s,a,x}* 464K bstring2021b-git.tgz 130K bstring2021b-src.tgz 5.0M comgt-0.42g-git.tgz 304K comgt-0.42g-src.tar 74.0K comgt-0.42g-src.tgz 150K comgt-0.42g-armv7l 224K comgt-0.42g-x86_64_newlibc 178K comgt-0.42g-x86_newlibc 156K comgt-0.42g-x86_oldlibc $ md5sum bstring2021b* comgt-0.42{d,g}-{g,s,a,x}* 2a0f084caf5fb685646dbc82fab4978a bstring2021b-git.tgz 74fe9f38a214fbf3890a715c6e952a4e bstring2021b-src.tgz 546099900afb5254854c925c19eb5b06 comgt-0.42d-git.tgz fa9a7a4ab048f3e7b1fd763ca5945ad5 comgt-0.42d-src.tar ae171258acc18affef6d7142b3814b64 comgt-0.42d-src.tgz a1cc9bbee70b3d3cfeca8ee8781a62d6 comgt-0.42d-armv7l b448fb19a85cb6bf6c05b51f0f1ff17a comgt-0.42d-x86_newlibc f77e30504c81682bcfadcc8056c38ee5 comgt-0.42d-x86_oldlibc cbc6269e3426bbd4b1a5158abece448c comgt-0.42g-git.tgz 12fa3061ddb1faf55447c28780daa5b3 comgt-0.42g-src.tar 28fc67779daf41b882b55bc4dfafae82 comgt-0.42g-src.tgz 72352d6489c2c76335b52a726c6c6a8a comgt-0.42g-armv7l f80a9846689eccdeeb7f351a64f52cc1 comgt-0.42g-x86_64_newlibc e9b2ce8fc73b30bc165afe96659ca11d comgt-0.42g-x86_newlibc 09974dd5b740436d4470fc4e1d3dc8d4 comgt-0.42g-x86_oldlibc $ sha256sum bstring2021b* comgt-0.42{d,g}-{g,s,a,x}* 5b4ee528a4ff4c8f9a78a723fbaeb33a954ea5f8722d387605679ac9a69e52ef bstring2021b-git.tgz d1a609414761c2c8937607a63421b8a9aeee9044d8736605aa71005c01d8c726 bstring2021b-src.tgz 20725941901cc53a0b0458c8b826bb505670fb74d5902d5fcff4ce98153b56c3 comgt-0.42d-git.tgz c14b417318bd104df4fe293c8d45cf8300fa9eafcc1739ea2f6db1a00f4c3a7b comgt-0.42d-src.tar df2958b04acd95c70d357bf5d71a1fbddc0c738403b32a4cfb0dfc189fc8f26f comgt-0.42d-src.tgz f06aa453be577fd6a6494ea885464d7073f836e55953b723210f88e8a3c8cc2f comgt-0.42d-armv7l 1e82066b296992e0093cfffd33a5fcee32c53ecd71550fc6da04523196497f58 comgt-0.42d-x86_newlibc fca58cdbc0a51913a01214ef7f3b446ebeed81f1e1ed7bab30132301ff35512c comgt-0.42d-x86_oldlibc 70b100f676623b38867e079c6def6748afe8d45131cb74a1b557ba5554da5ba4 comgt-0.42g-git.tgz abd2e57cbcbb39af2637d93b17a48f394d9d3e614131e98d88c846e3e199fbac comgt-0.42g-src.tar 75e483486811976e522f4799edd2e201964e997c611d259c12c23dee11cf7557 comgt-0.42g-src.tgz 692ffa611913bbc5cf919556070049c59bbbe699020bebd44e773bc4fbf8e819 comgt-0.42g-armv7l 49eb412f07fa263e7f3f836efba8c4e961c8b2d5e868a8687d507f8d7d7d5f77 comgt-0.42g-x86_64_newlibc 930a3b2a96ab16e9f79aa934de47e789b593091d2d0119049f19eee52e676b56 comgt-0.42g-x86_newlibc b63009cca8dfcd68d34a34e91128f89c74fe9289bd0a81861314ee1b76c7d618 comgt-0.42g-x86_oldlibc $
Most important change in 0.42a is the use of bstringlib (bstring2015.tgz).
comgt-0.42a-armv7l (right-click, save-as // Rechtsklick, Speichern als)
comgt-0.42a-x86_newlibc (right-click, save-as // Rechtsklick, Speichern als) (You cannot use this on old computers, please use 0.41c or compile by your own)
comgt-0.41c-armv7l (right-click, save-as // Rechtsklick, Speichern als)
comgt-0.41c-x86 (right-click, save-as // Rechtsklick, Speichern als)
$ du -shx comgt-0.41c-{g,s,a,x}* 1,5M comgt-0.41c-git.tgz 60K comgt-0.41c-src.tgz 92K comgt-0.41c-armv7l 96K comgt-0.41c-x86 $ md5sum comgt-0.41c-{g,s,a,x}* d5c81ea527bcecae3a7efaf898c57f9a comgt-0.41c-git.tgz 180a61362202d15a291c55c1afa65399 comgt-0.41c-src.tgz 3dc47ee5f7fd33d12d21c29212938ded comgt-0.41c-armv7l 168d7db36ecba9883a51e1208d790e96 comgt-0.41c-x86 $ sha256sum comgt-0.41c-{g,s,a,x}* 0c8266618bbc2fd08991dbde0bbde2e5ecf0005ad8a7e77b62eec2c49ec80a8c comgt-0.41c-git.tgz f72f70be3641b62235ecaa43ffdf044dede84a9273f3929dc76b35e2930233ac comgt-0.41c-src.tgz 19e2946728953c9327867637e03c509bfc8cdbd154ddf61681ba5db72688b171 comgt-0.41c-armv7l ac9754df172011a820af12ddebc3fc37e83c14545aab86fb21ac9dc824b04ce1 comgt-0.41c-x86 $<< >>Beispiel
$ ./comgt -s scripts/send-sms Trying list of devices Will wait for 5s for response. Empty line terminates. ################# ==SMS sending program== Number (no spaces etc): 017999999999 Message (one line): <RP-MTI> 81 <MR> 00 (Message-ID) <DA> 0cA1106726645199 (Number) <PID> 00 (no telematic type) <DCS> 00 (Coding scheme) <UDL> 63 (User data length in septets, hexadecimal) <UD> C474790E4ACFE9A072DA5D0651CB737A6BDA9CB240E47419D44ED341E377FB4C07A1C865B9BE9CA683D0743A5CF77AA9C5E5319A5E66BBC8E5D73C4D2FBFA8EF377BFE1ABFDB67FA2B051ABFC9E9B29C0EBAD7E5E4B20B (User data) Final: 81000cA1109799999999000063C474790E4ACFE9A072DA5D0651CB737A6BDA9CB240E47419D44ED341E377FB4C07A1C865B9BE9CA683D0743A5CF77AA9C5E5319A5E66BBC8E5D73C4D2FBFA8EF377BFE1ABFDB67FA2B051ABFC9E9B29C0EBAD7E5E4B20B Really? (type "yes"): yes AT+CMGS=100 Message probably has been sent. $ $ ./comgt-0.41c-armv7l -s scripts/command Type command at prompt. You may want to start with "AT+CFUN=1". Command loop will wait 5s for response. Use command "..%" to wait further. Command = "." (dot) terminates. ################# Trying list of devices Command: AT+CUSD=1,"*100#",15 Status: OK Status: +CUSD: 1,"Hi! Dein aktuelles Guthaben: 9,99 EUR Status: W�l bitte aus: Status: 1 Aufladen Status: 2 Guthaben & Verbrauch Status: 3 Spracheinstellungen Status: 4 Special offer",0 Command: AT+CUSD=1,"2",15 Status: OK Status: +CUSD: 1,"W�l bitte aus: Status: 1 Guthaben abfragen Status: 2 Bonus-Guthaben abfragen & mehr Infos Status: 3 QuickCheck Status: * Zur�k",0 Command: AT+CUSD=1,"3",15 Status: OK Status: +CUSD: 1,"Verbrauch in den letzten 7 Tagen: 5 Einheiten, 120 MB. Status: * Zur�k Status: # Hauptmen�,15 Status: ^MODE:5,5 Command: . ################# $ $ ./comgt -d /dev/ttyUSB2 -s scripts/ussd-chat You could start with "#99*" if your provider supported this. Command loop will wait 5s for response. Use empty command (= Enter) to wait further. Command = "." (dot) terminates. (2x "." needed when in conversation!) ################# USSD start phrase: *100# USSD input: <Enter> :: Hi! Dein aktuelles Guthaben: 9,99 EUR :: W�hl bitte aus: :: 1 Aufladen :: 2 Guthaben & Verbrauch :: 3 Spracheinstellungen :: 4 Special offer USSD input: 2 :: W�hl bitte aus: :: 1 Guthaben abfragen :: 2 Bonus-Guthaben abfragen & mehr Infos :: 3 QuickCheck :: * Zur�ck USSD input: 3 :: Verbrauch in den letzten 7 Tagen: 5 Einheiten, 120 MB. :: * Zur�ck :: # Hauptmen� USSD input: . USSD start phrase: . ################# $<
comgt(1) General Commands Manual comgt(1) NAME comgt - Option GlobeTrotter GPRS/EDGE/3G/HSDPA and Vodafone 3G/GPRS datacard control tool SYNOPSIS comgt -d device -ehstvVx script OPTIONS -d device set the device to be used to communicate with the data- card. If not specified then comgt trys /dev/noz2, /dev/ttyUSB2 and then /dev/modem -e turn on serial communications echo. -h display summary help and exit. -s don´t run the internal default script before an external script. -t change to an alternate line terminator (default "0). -v run in verbose mode. This traces scripts as they are ex‐ ecuted. It is intended to help in debugging scripts. -V Print Version information. -x for internal and external scripts, any reference to 115200 baud is converted to 57600. This is useful for data cards that don't like 115200 baud such as the Glo‐ beTrotter EDGE. DESCRIPTION comgt is a scripting language interpreter useful for establishing com‐ munications on serial lines and through PCMCIA modems as well as GPRS and 3G datacards. comgt has some features that are rarely found in other utilities of the same type. Features - Pre-defined built-in scripts for 2G/3G datacard control - Simple, BASIC-like script language. - Command-line and file sourcing of script. - Multi-response waitfor. - waitquiet permits line stabilization. - In-line text capture. - Multi-process support: fork, wait, kill, exit. - Debugging verbose and log output. - logging to file. - allocate pty - Open arbitrary channels as file descriptors (pty, existing fd, file) - Flow control: goto, gosub, return, if, else. - Low-impact on system resources. - Time commands and functions. - String manipulations (strictly bytewise). - Environment manipulation: env(), putenv. - External utilities system calls: system, exec. Supported GPRS and 3G datacards comgt has been tested against GlobeTrotter GPRS,EDGE, Combo EDGE, 3G, 3G EDGE, HSDPA and GlobeTrotter Fusion as well as Vodafone 3G. It can set the PIN and display information about datacards before a PPP con‐ nection is started. Additionally, because the GlobeTrotter and Voda‐ fone 3G/GPRS datacard have a secondary serial interface, these datac‐ ards can be monitored while a PPP connection is in existence and trans‐ ferring data. comgt is primarily designed to work with the GlobeTrotter range of dat‐ acards but should be compatible with any other GPRS or 3G datacard pro‐ vided its interface is implemented as one or more serial or USB serial devices and it is controlled and queried by an implementation of the Hayes command interface with the same AT command extensions used by the listed datacards. Using comgt comgt has only one function: to run a script. This may be one of a num‐ ber of "standard" internal scripts or an external script. Both types of script are invoked in the same way. The "standard" scripts are built into comgt and will work for serially connected modems, built-in modems, PCMCIA modems as well as the GlobeTrotter GPRS and the Vodafone 3G/GPRS datacards. There is a search priority order for scripts - 1)internal, 2)working directory, 3)/etc/comgt Built-in scripts comgt This runs the default internal script. Running comgt without any script specified, e.g., comgt -d /dev/ttyS1 it will check for a PIN and prompt you if it is required. The next thing it does is wait for the device to register, it then reports the signal strength. If you don´t specify a port with the -d option then /dev/modem is assumed. If the -s switch is not used then this default script is run before any external script. comgt help Lists these and the other options available. comgt info Lists the datacard configuration. comgt sig Prints the signal strength. comgt reg Prints the registration state. comgt 3G Puts a GlobeTrotter 3G/Fusion and Vodafone 3G into 3G network only mode (UMTS/HSDPA). comgt 2G Puts a GlobeTrotter 3G/Fusion and Vodafone 3G into 2G network only mode (GSM/GPRS/EDGE). comgt 3G2G Puts a GlobeTrotter 3G/Fusion and Vodafone 3G into 3G preferred mode (UMTS/HSDPA and GSM/GPRS/EDGE). comgt GTEDGE Use this command to initialise GlobeTrotter EDGE and GlobeTrotter Combo EDGE cards before doing anything else. (It switches on the radio). comgt USA Switch to 900/1900 MHz band for USA operation. GlobeTrotter GPRS datac‐ ards only. comgt EUROPE Switch to 900/1800 MHz band for European operation. GlobeTrotter GPRS datacards only. comgt PIN Test the SIM PIN status and use the environment variable COMGTPIN as the value . comgt APN Set the APN of the datacard to the value contained in the COMGTAPN en‐ vironment variable. Custom Scripts As well as built in scripts you can make your own. The following script sets a Vodafone 3G datacard or Option Fusion card´s UMTS mode to GPRS: #Set GPRS only mode set com 115200n81 set senddelay 0.05 waitquiet 1 0.2 send "AT_OPSYS=0^m" print "Setting GPRS only mode" If you saved the above script as GPRS you would call it like this: comgt GPRS If you needed to specify the port as well then do this: comgt -d /dev/ttyS1 GPRS You can also pass environment parameters to a comgt script via $env(). Replacing chat chat is a utility that comes with the ppp package (for Linux, anyway) that, with a set of expect-send string couples, does enough to connect most people to ISPs and such. While chat´s use is very simple, it isn´t very flexible. That´s where comgt takes over. comgt can be used in place of chat using the same strategy. For exam‐ ple, a pppd line reading: pppd connect \ ´chat -v "" ATDT5551212 CONNECT "" ogin: ppp \ word: whitewater´ \ /dev/cua1 38400 debug crtscts modem defaultroute Would, using comgt, read: pppd connect ´comgt -s /root/scripts/isp.scr´ /dev/cua1 38400 \ debug crtscts modem defaultroute And the isp.scr script would read: send "ATDT5551212^m" waitfor 60 "ogin:" send "ppp^m" waitfor 60 "word:" send "whitewater^m" Of course it then becomes trivial to make this script a whole lot more functional by adding code for busy detect, re-dialing, etc... Verbose output When the verbose option is turned on, comgt reports everthing on the standard error channel. If turned on from the command line (-v), the output contains 4 sections. - Command line argument actions These are actions taken because they were specified from the command line, such as opening a communication device (-d), etc... For these to be output, you must specify -v as the first argument. - List of arguments The number and list of arguments passed. This is useful in case you have a bunch of environment variables or quotes, back-quotes, back‐ slashes on the command line and you´re not sure what the script re‐ ally sees. - Script list A list of the script to execute. This may be a concatenation of the default internal script, unless this is suppressed by the -s option, and a script file. Every line is listed with its line number and character position. - Execution output List of commands as they are executed. The parser prints the line its currently on, starting from the exact point where its at to the end of the line. Multiple command groups on a single line produce multi‐ ple output lines. Verbose output may be mixed with script output (print, eprint or lprint.) Here´s an example: $ comgt -v -d/dev/cua1 -s blah.scr comgt 00:18:46 -> Verbose output enabled comgt 00:18:46 -> Script file: blah.scr comgt 00:18:46 -> argc:5 comgt 00:18:46 -> argv[0]=comgt comgt 00:18:46 -> argv[1]=-v comgt 00:18:46 -> argv[2]=-d/dev/cua1 comgt 00:18:46 -> argv[3]=-s comgt 00:18:46 -> argv[4]=blah.scr comgt 00:18:46 -> ---Script--- 1@0000 set com 38400n81 let a=2 2@0025 print "9x",a,"=",9*a,"\n" 3@0051 sleep 5 4@0059 exit 0 comgt 00:18:46 -> ---End of script--- comgt 00:18:46 -> @0000 set com 38400n81 let a=2 comgt 00:18:46 -> @0017 let a=2 comgt 00:18:46 -> @0025 print "9x",a,"=",9*a,"\n" 9x2=18 comgt 00:18:46 -> @0051 sleep 5 comgt 00:18:51 -> @0059 exit 0 Programming manual Syntax The syntax used for comgt scripts is rather simple, somewhat BASIC- like. A script is a non-tokenized, pure ASCII text file containing lines terminated by newline characters (Unix standard.) Scripts can be created and/or modified using any standard text editor (vi, vim, joe, pico, emacs, ed, microEmacs). Lines in a comgt script read like so: - Empty line - [indent]rem remark - [indent][{:|label} LABEL] command [arguments] rem remark - [indent][{:|label} LABEL] command [arguments] command [arguments] ... - [indent][{:|label} LABEL] command [arguments] \ command [arguments] command [arguments] rem remark (multi-line) Characters used for indentation are the space and tabulation charac‐ ters. The rem command makes the script parser skip the rest of the line. The rem command can also be written as "#" or "//". Labels consist of lowercase and uppercase letters and digits. Case is ignored in labels. Commands and their arguments are separated by spaces and/or tabs. Com‐ mand groups are separated by spaces, tabs, or newlines. Newlines can be escaped by adding a trailing \ to the first line. Then the command group continues in the next line which is specially useful for long if statements. Some commands allow or expect a gfd declaration (e.g. !5) in the argu‐ ment list, mostly before the first regular argument. The number of gfd can be an integer variable, e.g. let z=5 open recyclefd !z 0 Expressions must not contain spaces or tabs. This is ok : let n=x+76 This is not: let n= x + 76 Because this space ^ would terminate the let command group. Variables Integer and string variables have no correlation, so $a is independend from a Integer variables are called a-z, a0-a9, b0-b9, ..., z0-z9 String variables are called $a-$z, $a0-$a9, ..., $z0-$z9 Theses variables are effectively 0 or "" when unitialized. Some commands leave a resultcode in %. This can be saved to a integer variable with let command. It must be in brackets or at last place of the expression/bracket, however. let i=3+% let i=(%)+3 let i=(2+%)+1 Special variable % Some commands leave a resultcode in %. This can be saved to a integer variable with let command. It must be in brackets or at last place of the expression/bracket, however. let i=3+% let i=(%)+3 let i=(2+%)+1 Special variable v3r v3r is a variable which is guaranteed to be unequal to r on new comgt versions > 0.42e This is useful for those who want to write comgt scripts for all comgt versions, especially 0.32 (last known version be‐ fore my fork). You can safely try v3r pseudo-variable before queriing $versionnumber() or $version() like this: if v3r=r goto old print "***^^ NEW * IRIDESCENT * DAZZLING * REFACTORED * VERSION ^^***^*" print "version=",$versionnumber()+"\n" # this should be any >= 0.42e goto done :old let t=6 let a=l33t print a," <- this is number six, isn't it?\n" :done Error reporting When comgt detects a script error, it immediately turns on verbose mode, generates a dump (see the dump command), reports the error in three lines and stops the execution. The first line reported is the command group being executed, the second one shows where the parser got and the third line reports the character position of the program counter, the error and the exit code. Here´s an example: $ comgt -vs blar2.scr Where the blar2.scr script is: inc n dec d3 let a=58/3 let $d="fod" let c=1/0 let $y4="sdfgsdfgsdfg" The trace and error report looks like this: comgt 11:20:15 -> Verbose output enabled comgt 11:20:15 -> Script file: blar2.scr comgt 11:20:15 -> argc:3 comgt 11:20:15 -> argv[0]=comgt comgt 11:20:15 -> argv[1]=-vs comgt 11:20:15 -> argv[2]=blar2.scr comgt 11:20:15 -> ---Script--- 1@0000 inc n 2@0007 dec d3 3@0015 let a=58/3 4@0027 let $d="fod" 5@0041 let c=1/0 6@0052 let $y4="sdfgsdfgsdfg" comgt 11:20:15 -> ---End of script--- comgt 11:20:15 -> @0000 inc n comgt 11:20:15 -> @0007 dec d3 comgt 11:20:15 -> @0015 let a=58/3 comgt 11:20:15 -> @0027 let $d="fod" comgt 11:20:15 -> @0041 let c=1/0 comgt 11:20:15 -> -- Error Report -- comgt 11:20:15 -> ----> ^ comgt 11:20:15 -> Error @49, line 5, Division by zero. (6) Exit codes When comgt terminates, it does so with an "exit code". That is a num‐ ber passed back to the calling process to signify success or failures. In every-day Unix, 0 (zero) means success and everything else means whatever the author of the program wants it to mean. In a shell script, or directly on the command line, you may look at the content of $? after having called comgt to examine its exit code. Example: #!/bin/sh comgt /root/bin/call-isp if [ $? != 0 ]; then echo "Oops! Something went wrong." fi Internal comgt error codes are as follows: 0 : No problems whatsoever. Apparently. 1 : Communication device problems. 2 : Console (tty) device problems. 3 : Memory problems. 4 : File or pipe problems. 5 : Syntax errors. 6 : Division by zero. 7 : Variable mis-management. 8 : System problems. (Couldn´t call /bin/sh or some such) 9 : Internal problems. They do never happen. Commands Command : : Alias: label Description : Notes an anchor point for goto or gosub to branch to. Syntax : Keyword must not contain any special characters. Note : Must be first statement in a line. See Also : goto, gosub, return. Example: :loop gosub bravo print "The time is ",$time(),"\n" sleep 1 goto loop label bravo print "Twonk!\n" return Command : abort Description : Causes comgt to call abort() and produce a core dump. Syntax : abort See Also : dump, exit. Command : cd Description : Change directory. Syntax : cd directory Notes : -1 is returned in % if the change could not be made. Notes : directory is a string and thus could be a variable. See Also : $cwd(). Example: cd "duh" if % != 0 print "Could not cd into duh.\n" Command : close Description : closes file previously opened with open. Syntax : close file Syntax : close com / close hardcom Syntax : close gfd !gfd See Also : open. Command : dec Description : Decrements the content of an integer variable by 1. Syntax : dec x Notes : x is from a to z or a0 to z9. Notes : Note that "let x=x-1" also works. See Also : let, inc. Command : dump Description : Lists all non-zero integer variables and modified string Description : variables as log entries (standard error channel.) Syntax : dump See Also : abort, exit Command : else Description : Alternatively execute commands if last "if" tested false. Syntax : else commands... See Also : if Example: if w<350 print "Wow! Imagine that.\n" else print "Rush Limbaugh is a big fat bastard.\n" Command : eprint Description : print a comma-separated list of arguments on stderr. Syntax : eprint var,stringvar,"text",... Notes : Like print but on the standard error file descriptor. Notes : The error output can be re-directed with "2>file" on Notes : the command line. See Also : print. Command : exec Description : Replaces current comgt process with another process. Syntax : exec "command -args..." See Also : system, fork. Example: #Finished script, call cu. exec "cu -l "+$dev()+" -s "+$baud() Command : exit Description : terminates script execution with exit code. Syntax : exit exit_code See Also : abort, dump. Example: :error exit 1 :smeggit exit 0 Command : flash Description : Toggles DTR on communication device for a specified time. Syntax : flash float_constant Notes : float_constant is precise down to 1/100th sec. Notes : Causes modem to drop carrier or go to command mode, Notes : depending on modem settings. Setting the baud rate to 0 Notes : for a time has the same effect. See Also : sleep, set com. Example: :disconnect flash 0.5 exit 0 Command : fprint Description : print a comma-separated list of arguments in a file. Syntax : fprint var,stringvar,"text",... Notes : Like print but appended to a file previously opened Notes : by open. See Also : print. Command : fork Description : forks comgt process in two. Both processes continue Description : executing the script. Syntax : fork Notes : % returns 0 for child process, new process ID for Notes : parent or -1 for error. See Also : wait, kill, pid(), ppid(). Example: fork if % = -1 goto error if % = 0 goto child :parent ... Command : get Description : get string from communication device. Syntax : get timeout [!gfd] "terminators" $string Notes : timeout is a float constant, terminators is a Notes : list of characters that, when received, terminate Notes : get. Terminators are ignored when received first. See Also : waitfor. Example: waitfor 60 "connect" if % != 0 goto error get 2 " ^m" $s print "Connection parameters: ",$s,"\n" Command : gosub Description : calls a subroutine. Syntax : gosub label Notes : Currently, comgt only supports 128 levels of gosub Notes : calls (enough!) See Also : :, goto, return. Example: gosub routine sleep 1 gosub routine goto end :routine print "Flim-flam!\n" return Command : goto Description : Sends execution somewhere else in the script. Syntax : goto label See Also : :, gosub, return. Example: :win95 print "Today I want to go and use Linux, thank you.\n" goto win95 Command : hset Description : Set the hundreds timer. Syntax : hset value Notes : This command resets the hundreds of seconds timer to Notes : a value for htime to start from. See Also : htime(). Example: hset 0 :loop print "Time in 1/100 of a sec.: ",htime(),"\n" sleep 0.01 goto loop Command : if Description : tests a condition Syntax : if test_condition commands... Notes : Conditionnaly executes commands if test condition is true. Notes : Test operators are = (equal), != (not equal), Notes : <> (not equal to) < (less than), > (greater than), Notes : <= (less or equal), >= (greater or equal). Notes : All operators can be used with integers and strings. Notes : If test_condition is false, if skips to Notes : the next line. See Also : else. Example: if n>30 print "Oh-ho! too many sheep!\n" goto error if n=17 print "Hurray! we´ve enough sheep\n" goto party if n<17 print "Murray, get more sheep.\n" goto getmore if $z < "Marmaluke" goto ... if 3*a>5+b goto ... Command : inc Description : increments the content of an integer variable by 1. Syntax : inc x Notes : x is a-z or a0-z9. See Also : dec, let. Command : input Description : input string from keyboard into string variable. Syntax : input $x, input !gfd $x Notes : input terminates entry only with the ENTER key. Notes : Spaces, tabs and other funny characters are all Notes : stored in the variable. Notes : 0 is returned in % if there's input, %=1 if there was Notes : a timeout (but maybe some bytes have been read), Notes : %=-2 or lower on error, where -10 and lower are Notes : system errors (-11 is errno=1, -12 is errno=2, ...). See Also : set echo. Example: print "Enter your full name :" input $n4 Command : kill Description : Sends a signal to a process. Syntax : kill signal processID Notes : Both signal and processID are integer values. Same as Notes : standard unix kill except that signal aliases are not Notes : accepted and signal is not optional. Notes : 0 is returned in % if the signal could be sent, -1 Notes : otherwise. Notes : Signal 0 can be used to detect process existance. See Also : wait, pid(), ppid(). Example: fork let p=% if p = 0 goto child sleep 300 kill 15 p sleep 1 kill 0 p if % != 0 print "Child terminated\n" goto ok print "Could not terminate child!\n" kill 9 p sleep 1 kill 0 p if % = 0 print "Could not kill child!\n" goto error print "Child killed.\n" :ok ... Command : let Description : Does a variable assignment. Syntax : let x=content Notes : x is [$]a0-z9. See Also : inc, dec. Example: let a=5 let b=(time()-a)+5 let y7=6809 let z=0%11010111 #Binary let z=077324 #octal let z=0xf5b8 #hexadecimal let $c="Daniel " let $d=$c+" Chouinard" let $s5="Frimpin´ Jeosaphat!" Command : lprint Description : Print a comma-separated list of arguments to the log. Syntax : fprint var,stringvar,"text",... Notes : Like print but printed like a log entry if verbose is on. Notes : logging is sent to stderr. See Also : print, eprint, fprint. Command : open Description : Opens a file or a communication device. Syntax : open com device, open com - Syntax : open file FILE, open file !gfd FILE Syntax : open pty !gfd, open recyclefd !gfd fdnum Syntax : open socketpair !gfd1 !gfd2 Notes : If gfd is given, send sets resultcode % to Notes : %=0 (all fine) Notes : %=-1 (gfd/gfd1 already open) Notes : %=-2 (gfd2 already open or same as gfd1) Notes : %<-10 (syscall error, errno = 0-%-10) See Also : close. Example: open com /dev/cua1 set com 38400n81 open file "/tmp/log" fprintf "This is a log\n" close file open socketpair !8 !9 fork if % < 0 let a=% print "Error ",a,"0 exit 0-a if % > 0 goto proceed close gfd !8 let o=osnumber(!9) # (you have to install package 'socat' on your distribution) exec "socat FD:"+o+" TCP4-LISTEN:4321" # IPv4 explicitely. :proceed close gfd !9 input !8 $r print "Got "+$r+" from network0 Command : print Description : print a comma-separated list of arguments. Syntax : print [!gfd] var,stringvar,"text",... Notes : Spaces and newlines are not automatically added. Notes : Sets resultcode % if used with gfd. See Also : eprint, fprint, lprint. Example: let b=26 let $c="text variables" print "Contstant text ",b," ",$c," time: ",$time(),"\n" print !5 "This goes to gfd 5\n" if %!=0 print "Couln't write to gfd!\n" Command : putenv Description : Sets an environment variable. Syntax : putenv "var=content" Notes : Environment variables are automatically exported, Notes : never returned. Children processes inherit the Notes : environment. See Also : $env(). Example: putenv "SCRIPTDIR=/usr/lib/comgt/scripts" system "dothat" # dothat reads env. var. SCRIPTDIR... Command : rem Aliases: #, // Description : Remark. Rest of line is ignored. Syntax : Note that a space must follow "rem". Example: #This is a remark // So is this rem This ain´t no disco. Command : return Description : Returns from subroutine. Syntax : return See Also : gosub. Command : send Description : sends a string to the communication line (modem usually). Syntax : send [!gfd] string Notes : Carriage return (ENTER) is not sent automatically Notes : (use ^m). Notes : If gfd is given, send sets resultcode % to Notes : %=0 (all fine) Notes : %>0 (number of bytes which have not been send) (inprobable) Notes : %=-1 (gfd not open) Notes : %=-2 (other sie of gfd, specially pty, not open) Notes : %<-10 (syscall error, errno = 0-%-10) Example: send "atdt555-1212^m" send $g+"^m" send "The time is "+$time()+"^m^j" Command : set Description : sets working parameters. Syntax : set parameter value Notes : Command Description ----------------------------- ------------------------------------------------- set echo on|off Keyboard echo on-screen. set comecho on|off Received characters echoed on-screen. set senddelay time_constant In-between character delay for "send" set ignorecase on|off Case sensitivity for "waitfor". Default=on. set clocal on|off clocal on = ignore modem signals set umask mode file mode creation defaults. See man umask. set verbose on|off verbose on = debug output enabled. set com com_params communication parameters. ex.: 19200n81, 300e71 baud ||| Parity | Data bits | Stop bits | Example: set echo off print "Password :" input $p print "\n" set echo on set comecho on set clocal on set senddelay 0.1 set ignorecase on set com 38400n81 set umask 022 # Must be octal (leading zero) ... Note on clocal: If want your script to keep working after the carrier detect signal has dropped, set clocal on, otherwise, a CD drop causes the device line to close (hang up). This could happen if, let´s say, your script calls and connects, then disconnects or drops dtr (flash), then tries to re-connect again. Command : sleep Description : Pauses execution. Syntax : sleep float_constant Notes : Float_constant is precise down to 1/100th sec, unless Notes : more than 100 seconds, in which case the precision Notes : falls down to 1 sec. Example: sleep 0.06 sleep 3 sleep 86400 /* A whole day */ Command : system Description : Calls a system (unix) command Syntax : system "command" See Also : exec. Example: :dir print "listing of directory ",$cwd(),\n" system "ls -l |more" Command : testkey Description : Tests keyboard for keystroke, returns 1 in % if present. Syntax : testkey Notes : Can only test for ENTER key. Future versions of comgt Notes : will test for more and return keycodes in %. See Also : input. Example: let n=1 :loop print n," sheep... ZZZzzz...\n" sleep n inc n testkey if % = 0 goto loop Command : wait Description : Wait for a child process to terminate. Syntax : wait Notes : Process ID of terminated child is returned in % See Also : fork, kill. Example: fork let p=% if p=0 goto child if p=-1 goto error print "Waiting for child to finish..." wait print "\n" if %!=p print "Wait got wrong PID!\n" goto error print "Child is done.\n" Command : waitfor Description : Waits until one of a list of strings is received Syntax : waitfor timeout [!gfd] "string1","string2","string3"... Notes : Timeout is a floating time constant in seconds with 1/100th Notes : second accuracy. waitquiet returns 0 for the first string Notes : received, 1 for the second, etc... and -1 for a timeout. Notes : Case is ignored by default unless ignorecase is set to off. See Also : get. Example: :dial send "atdt555-4411^m" waitfor 60 "no carrier","busy","no dial tone","connect" if % = -1 goto timedout if % = 0 goto nocd if % = 1 goto redial if % = 2 goto error if % = 3 goto connected Command : waitquiet Description : Waits until communication line stops receiving for a time. Syntax : waitquiet timeout quiettime [!gfd] Notes : Both timeout and quiettime are floating time constants Notes : with 1/100th sec. accuracy. Usefull for "swallowing" Notes : incoming characters for a while or waiting for an Notes : unknown prompt. Example: :closecon send "logoff^m" waitquiet 10 0.5 send "yes^m" Integer functions I-Function : Access Description : Verifies access rights to a file Syntax : let x=access("/tmp/file","frwx") Notes : The second string contains one or more of Notes : ´f´,´r´,´w´,´x´ to repectively check Notes : existence, read, write and execute permissions. Notes : Under root id, the only useful check is ´f´, as Notes : all others will return true. Return Value: 0 if the file exists, is readable, writable, Return Value: executable, or -1 if not. See Also : man access(2) I-Function : baud Description : Returns current baudrate of communication line. Syntax : let x=baud() Notes : Does not necessarily match the modem connection speed. See Also : $baud(). I-Function : len Description : Returns the length of a string. Syntax : let x=len($s) Notes : "" is zero. String processing currently may have a maximum Notes : length of 1024 characters. comgt sometimes may not handle string Notes : overflow (yet to be reviewed). I-Function : htime Description : Returns hundreds of seconds since start of script. Syntax : let x=htime() Notes : Set to a specific value with hset. See Also : hset. I-Function : osnumber Description : Returns the actial number of the gfd (-1 if not open) Syntax : let x=osnumber(!5) See Also : $name, $ptsname(), $type() I-Function : pid Description : Returns process ID number of current process (comgt) Syntax : let x=pid() See Also : ppid(), fork I-Function : ppid Description : Returns process ID number of parent process. Syntax : let x=ppid() Notes : Can be used by forked child to detect parent Notes : process. I-Function : time Description : Returns time in seconds since Jan 1, 00:00:00 1970 GMT. Syntax : let x=time() Notes : Used to calculate time differences. See Also : $time() I-Function : val Description : Returns value of string. Syntax : let x=val($x) Notes : String is not an expression; must only contain [0-9] Notes : characters. Future versions of comgt will be able to Notes : evaluate expressions. (Maybe) (This was written 6 Notes : years ago.) I-Function : verbose Description : Returns value of verbose setting. Syntax : let x=verbose() Notes : 0=off, 1=on. String functions S-Function : basename Description : Returns basename part of path. Syntax : let $x=$basename($p) Notes : $basename("/usr/bin/more")="more" Notes : Path seperators are inter-OS, so slash (/) and Notes : backslash (\) count. Notes : Not completely conforming to typical posix behaviour See Also : $dirname(). S-Function : baud Description : Returns string representation of current baud rate. Syntax : let $x=$baud() Notes : Defined by "set com" See Also : baud(), set com. S-Function : cwd Description : Returns current working directory pathname. Syntax : let $x=$cwd() See Also : cd. S-Function : dev Description : Returns current communication device pathname. Syntax : let $x=$dev() Notes : defined by "-d" command line argument or "open com" See Also : open com. S-Function : dirname Description : Returns directory name part of path. Syntax : let $x=$dirname($p) Notes : $dirname("/usr/bin/more")="/usr/bin" Notes : Path seperators are inter-OS, so slash (/) and Notes : backslash (\) count. Notes : Not completely conforming to typical posix behaviour See Also : $basename(). S-Function : env Description : Returns content of an environment variable Syntax : let $x=$env("HOME") Notes : Non-existant variables return an empty string. See Also : putenv. S-Function : hex Description : Converts value to hexadecimal representation Syntax : let $x=$hex(x) Notes : Letters a-f in lowercase, no preceding "0x" See Also : $hexu(), $oct(). S-Function : hexu Description : Converts value to hexadecimal representation Syntax : let $x=$hex(x) Notes : Letters A-F in uppercase, no preceding "0x" See Also : $hex(), $oct(). S-Function : hms Description : Converts number of seconds into time string Syntax : let $x=$hms(x) Notes : Format is "HH:MM:SS". Useful for chronometer displays Notes : Use with "time()", do not try to increment a variable Notes : every second using "sleep 1". (See ISP script example) Notes : Format becomes "HHH:MM:SS" after 99 hours, 59 minutes, Notes : 59s... See Also : time(). S-Function : left Description : Returns left portion of a string Syntax : let $x=$left($s,l) Notes : $s=Source string, l=length Notes : If l<0 the left portion is returned so that the |l| rightmost Notes : bytes are missing. Notes : |l| must be less than the length of the string. See Also : $right(), $mid(). S-Function : mid Description : Returns midsection of a string. Syntax : let $x=$mid($s,s,l) Notes : $s=Source string, s=start, l=length Notes : s must be less than the length of the string, l can be Notes : some huge number (9999) to return the right side of a Notes : string to the end. the first character of a string is Notes : position 0, not 1. See Also : $right(), $left(). S-Function : name Description : Returns name of gfd ("" if not set or generic name or symlink Description : name if type is 'p' Syntax : let $x=$name(!5) See Also : $ptsname(), $type(), osnumber() S-Function : oct Description : Converts value to octal representation. Syntax : let $x=$oct(x) See Also : $hex(), $hexu(). S-Function : pdu7bit2txt Description : Transforms a plain text (7-bit GSM encoding) to a hexadecimal SMS user data string Syntax : let $x=$txt2pdu7bit("Blabla") See Also : $txt2pdu7bit(). S-Function : ptsname Description : Returns the name of the pty slave device of a gfd. Syntax : let $x=$ptsname(!gfd) Notes : $ptsname(!5) returns something like "/dev/pts/7" Notes : Script exits with error if this gfd is no pipe. See Also : open, $name(), $type(), osnumber() S-Function : right Description : Returns right portion of a string. Syntax : let $x=$right($s,l) Notes : $s=Source string, l=length Notes : If l<0 the right portion is returned so that the |l| leftmost Notes : bytes are missing. Notes : |l| must be less than the length of the string. See Also : $left(), $mid(). S-Function : rpipe Description : Returns the first line from a system piped command Syntax : let $x=$rpipe("/bin/ls |grep myfile") Notes : Not very useful unless used with head, tail, grep, Notes : etc... See Also : system. S-Function : time Description : Returns 24 character local time string Syntax : let $x=$time() See Also : time(). Notes : Time is in this format: Mon Apr 8 14:21:22 1996 012345678901234567890123 1 2 S-Function : tolower Description : Returns lowercase´d string. Syntax : let $x=$tolower($y) S-Function : toupper Description : Returns uppercase´d string. Syntax : let $x=$toupper($y) S-Function : txt2pdu7bit Description : Transforms a plain text (7-bit GSM encoding) to a hexadecimal SMS user data string Syntax : let $x=$txt2pdu7bit("Blabla") See Also : $pdu7bit2txt(). Example : let $a="D474BB2C9BD6E566D054072296DD2061789E9EC3E5E5F41C647FBB413118EB560315EBF237081D1697DDA07B5A0E0A8BCF65717D8CA6BB404679B9EE26B3D36374197494FB3D651688584EBB41F827B4452D87DB" let $b=$pdu7bit2txt($a) let $c=$txt2pdu7bit($b) print $b+"\n=\n"+$c S-Function : type Description : Returns type of gfd ("" or one-byte-string) Syntax : let $x=$type(!5) See Also : $name(), $ptsname(), osnumber() S-Function : version Description : Returns the full version string of comgt in format Description : comgt version <number> Copyright <names> (c) <years> Syntax : let $x=$version() Notes : This is the same string you get with comgt -V See Also : $versionnumber() and special variable v3r S-Function : versionnumber Description : Returns the version number of comgt which usually has format Description : 0.<number><letter> Syntax : let $x=$versionnumber() See Also : $version() and special variable v3r Test operators Operator Description Example Result = equal if 1+2=3 yes != not equal if 1+2!=3 no <> not equal if 1+2<>3 no > Greater than if 1+3>3 yes < Less than if 1+3<3 no >= Greater or equal if 3>=3 yes <= Greater or equal if 2<=3 yes Strings can be compared using the same operators. "aaa" < "aab", "aaaa" > "aaa", "Test" != "test", "One" = "One", "A" > "a", "Fumble" <= "Fumigate", "Farsical" <> "Comedic" Note that "set ignorecase on" does NOT apply to string comparisons. Expression operators Operator Description Example Result + Addition let a=2+2 4 + Concatenation let $b="aa"+a+"bb" "aa4bb" - Substraction let e=2-5 -3 * Multiplication let f=11*2 22 / Division let g=34/11 3 & Bit-Wise AND let h=42&7 2 | Bit-Wise OR let a=42|5 47 ^ Bit-Wise XOR let a=42^7 45 Mixed expression examples: #Returns number of seconds since 00:00:00 let $t=$time() #Take a snapshot. let a=(val(mid$($t,11,2))*3600)+(val(mid$($t,14,2))*60)+val(mid$($t,17,2)) #Notice the extra sets of parenthesis because comgt´s expression #evaluator is brain-dead. #For example, 5-2+1 should give you 4, right? Well, according to #getvalue(), it actually gives 2, because it does it somewhat from #right to left. #So to evaluate 5-2+1 correctly, use (5-2)+1. If you´re using #simple, two-element calculations, don´t worry about it. #5-2 will give you 3. #Concatenation (Calls cu) exec "cu -l "+$dev()+" -s "+$baud()" #In a test condition if a+c > strlen($c) goto toomuch #String comparison let $t=$mid($time(),11,8) if $t > "19:59:59" print "Too late for that!\n" goto toolate if $t < "08:00:00" print "Too early!\n" goto tooearly if $t = "00:00:00" print "Oh god! It´s Twinkee time!\n" KNOWN FEATURES The getvalue() parser. It makes me laugh so I think I´ll leave it that way. - Daniel.Chouinard@pwc.utc.com ENVIRONMENT VARIABLES COMGTPIN - the 4 digit pin of the SIM for use by PIN script COMGTAPN - the APN to write to the data card, used by the APN script. AUTHORS Daniel.Chouinard <Daniel.Chouinard@pwc.utc.com> wrote the original dcon utility. Paul Hardwick <paul@peck.org.uk> updated it for the latest compilers, provided the built-in script functionality and tested it against GPRS and 3G datacards. Martin Gregorie <martin@gregorie.org> wrote the original manpage for comgt from the dcon documentation and packaged comgt for distribution. History Daniel Chouinard wrote most (90%) of dcon back in 1989 when he started doing Unix Apps tech support mostly by modem to customer systems. He was tired of typing all those passwords and funny call-charging codes everytime he used cu. Also, the company he worked for needed a system that would log call times and estimated costs. Thus dcon was born. Six or seven years later (1996) and he was using pppd to connect to his ISP site. He was more or less happy with chat but found it lacked flow control and multiple response checks from "atdt...". He wanted it to do different things for "no carrier", "no dial tone", and "busy". Al‐ though he thought that chat would probably be enhanced someday, when he found dcon.c on one of his old 45M tapes he tried compiling it on his Linux box and, lo and behold, it did. In the end, he added a few things to it (kill, fork, wait, 1/100 sec. times) and left it at that. A couple of years ago Paul Hardwick found the program, dcon 0.97, last modified in 1996. The purpose of this program was to run scripts that would control Linux serial ports. The implementation was very similar to something he had written for Windows. Anyway, rather than reinvent he contacted the author, Daniel Chouinard, and asked his permission to reuse the code. Happily he gave permission and a basic but useful utility called comgt was created. Paul takes no credit for the engine, apart from making it compatible with todays compilers. It is basically dcon repackaged. 20 October, 2006 comgt(1)<<