C-Kermit Scripting Tutorial and Library
C-Kermit Scripting Tutorial and Library:
https://kermitproject.org/ckscripts.html
Useful Options:
--unbuffered Force unbuffered console i/o.
--nolocale Disable use of locale for messages and strings.
--noperms Disable file-transfer Permissions attribute.
--nointerrupts Disable keyboard interrupts.
--nopush Disable external command execution.
--timeout:
--termtype:name Choose terminal type.
--rcharset:name Name of remote terminal character set.
--user:name Username.
Useful Commands:
- SHOW FEATURES: to see what might have been excluded when build or unavailable on certain platforms.
- "Ctrl + \ + C" to break current blocking operations(hold down the "Ctrl" key and press then "" key then "C" key);
- ?: get a list of all C-Kermit's commands, type a question mark (?) at the prompt.
- HELP
To get a description of any command, for example: help send
- (backslash) is escape character", used to introduce variable names, function invocations, and so on. If you need to include a literal backslash in a command, type two of them, e.g.:
get c:\\k95\\k95custom.ini
. It also introduces variable names and calls to built-in functions.
Getting Help within a Command
A question mark (?), typed at any point in a command, produces a message explaining what is possible or expected at that point. Depending on the context, the message can be a brief explanatory phrase, a menu of valid keywords, or a list of files.
- If you type a question mark at the prompt, you’ll see a list of all C-Kermit’s top-level commands.
- If you type a letter s at the prompt and then question mark, Kermit lists the commands that start with s:
C-Kermit>s? Command, one of the following:
save server sleep status switch screen set sort stop
script sexpressionspace succeed
search shift spawn support
send show statisticssuspend
C-Kermit>s
After the menu or help message is displayed, you can continue the command from where you left off. The s is still there, and now you can type a letter e and another question mark to see which commands start with se:
C-Kermit>se? Command, one of the following:
search send server set sexpression
C-Kermit>set
INITIALIZATION FILE
When you start C-Kermit, it executes commands from an initialization file in your home directory unless it is given the -Y or -y command-line option.
Platform | Filename | Location |
---|---|---|
Unix:Linux,macOS,BSD,etc | .kermrc | Your home (login) dir. |
MS Windows | k95custom.ini | \v(appdata) (your app. data dir.) |
IBM OS/2 | k2custom.ini | \v(appdata) (your app. data dir.) |
VMS, OpenVMS | ckermit.ini | Your home (login) dir. |
Other | ckermit.ini | Your home (login) dir. |
Your initialization file can contain any Kermit commands at all, as well as comments.
A typical use would be to define macros that you want to be able to execute whenever you're using C-Kermit.
To remind you that it's being executed you might want to include a line like this in it:
echo C-Kermit \v(fullversion) executing \v(cmdfile)...
- Command Files, Macros, and Scripts
A file containing Kermit commands is called a Kermit command file or Kermit script.
It can be executed with Kermit's TAKE command:
(/current/dir) C-Kermit> take commandfile
(where "commandfile" is the name of the command file).
In Unix only, a Kermit command file can also be executed directly by including a "kerbang" line as the first line of the file:
#!/usr/local/bin/kermit +
That is, a top line that starts with "#!", followed immediately by the full path of the Kermit executable, and then, if the Kermit script is to be given arguments on the command line, a space and a plus sign. The script file must also have execute permission:
chmod +x commandfile
COMMAND LINE:
Finally, if Kermit's first command-line option is a Telnet, FTP, IKSD, or HTTP URL,
Kermit automatically makes the appropriate kind of connection and, if indicated by the URL, takes the desired action:
kermit telnet:xyzcorp.com ; Opens a Telnet session
kermit telnet://olga@xyzcorp.com ; Ditto for user olga
kermit ftp://olga@xyzcorp.com/public/somefile.zip ; Downloads a file
kermit kermit://kermit.columbia.edu/kermit/f/READ.ME ; Ditto for IKSD
kermit iksd://kermit.columbia.edu/kermit/f/READ.ME ; (This works too)
kermit https://kermitproject.org/index.html ; Grabs a web page
kermit https://wwws.xyzcorp.com/secret/plan.html ; Grabs a secure web page
- COMMAND-LINE OPTIONS
Usage:
1. kermit [filename] [-x arg [-x arg]...[-yyy]..] [ {=,--,+} text ] ]
2. kermit URL
-x is an option requiring an argument;
-y is an option with no argument.
- If the first argument is the name of a file, interactive-mode commands are executed from the file.
- The '=' (or "--") argument tells Kermit not to parse the remainder of the command line, but to make the words following '=' available as %1, %2, ... %9.
- The "+" argument is like "=" but for use in "kerbang scripts" (explained below).
- A second command-line format allows the one and only argument to be a Telnet, FTP, HTTP, or IKSD URL.
Order of Execution:
- The command file (if any).
- The initialization file, if any, unless suppressed with -Y.
- The customization file (if it is executed by the initialization file).
- The command-line URL (if any, and if so, execution stops here).
- Command-line options (if any).
- Interactive commands.
Some cmd.line options can cause actions(such as -s); others just set parameters.
- Kermit exits when finished unless also given the -S ("stay") option, If any action options are included on the cmd. line, .
- Kermit issues its prompt and waits for you to type commands, If no action options are given, no initialization or command files contained an EXIT or QUIT command, and no fatal errors occurred.
C-Kermit Invocation:
$ kermit -s ckermit.tar.gz
('$' is the shell prompt; kermit -s ckermit.tar.gz is what you type, followed by Return or Enter.)
C-Kermit has three kinds of commands:
- regular single-letter command-line options,
- extended-format command-line options,
- interactive commands.
regular single-letter command-line options
Like most Unix commands, C-Kermit can be be given options on the command line.
In other words, you don't have to use C-Kermit's command-line options, but they are available if you want to.
By the same token, you don't have to use its interactive commands either -- you can use either or both in any combination.
Here is a list of C-Kermit's single-letter command-line options, which start with a single dash (-), in ASCII ("alphabetical") order. Alphabetic case is significant (-A is not the same as -a). The Action column contains **Y for action options **and N for non-action options.
Option | Action | Description |
---|---|---|
-0 | N | 100% transparent Connect state for "in-the-middle" operation: 8 bits, no parity, no escape character, everything passes through. |
-8 | N | Connection is 8-bit clean (this is the default in C-Kermit 9.0 and later). Equivalent to the EIGHTBIT command, which in turn is a shortcut for SET TERMINAL BYTESIZE 8, SET COMMAND BYTESIZE 8, SET PARITY NONE. |
-9 arg | N | (digit nine) Make a connection to an FTP server. Equivalent to the FTP OPEN command. Argument: IP-address-or-hostname[:optional-TCP-port]. NOTE: C-Kermit also has a separate FTP command-line personality, with regular FTP-like command-line syntax. More about this below. |
-A | N | Kermit is to be started as an Internet service (IKSD) (only from inetd.conf). |
-B | N | Kermit is running in Batch or Background (no controlling terminal). To be used in case Kermit doesn't automatically sense its background status. Equivalent to the SET BACKGROUND ON command. |
-C arg | N | Interactive-mode Commands to be executed. Argument: Commands separated by commas, list in doublequotes. |
-D arg | N | Delay before starting to send in Remote mode. Equivalent to the SET DELAY command. Argument: Number of seconds. |
-E | N | Exit automatically when connection closes. Equivalent to SET EXIT ON-DISCONNECT ON. |
-F arg | N | Use an open TCP connection. |
-G arg | Y | Get file(s) from server, send contents to standard output, which normally would be piped to another process. Argument: Remote file specification, in quotes if it contains metacharacters. Also see: -g, -k. |
-H | N | Suppress program startup Herald and greeting. |
-I | N | Tell Kermit it has a reliable connection, to force streaming to be used where it normally would not be. Equivalent to the SET RELIABLE ON command. |
-J arg | N | "Be like Telnet." Like -j but implies -E. Argument: IP hostname/address optionally followed by service. NOTE: C-Kermit also has a separate Telnet command-line personality, with regular Telnet-like command-line syntax. More about this below. |
-L | N | Recursive directory descent for files in -s option. |
-M arg | N | My user name (for use with Telnet, Rlogin, FTP, etc). Equivalent to the SET LOGIN USER command. Argument: Username string. |
-O | Y | (Uppercase letter O) Be a server for One command only. Also see: -x. |
-P | N | Don't convert file (Path) names of transferred files. Equivalent to SET FILE NAMES LITERAL. |
-Q | N | Quick Kermit protocol settings. Equivalent to the FAST command. This is the default in C-Kermit 7.0 and later. |
-R | N | Remote-only (this just makes IF REMOTE true). |
-S | N | Stay (enter command parser after action options). |
-T | N | Force Text mode for file transfer; implies -V. Equivalent to SET TRANSFER MODE MANUAL, SET FILE TYPE TEXT. |
-V | N | Disable automatic per-file text/binary switching. Equivalent to SET TRANSFER MODE MANUAL. |
-Y | N | Skip (don't execute) the initialization file. |
-a arg | N | As-name for file(s) in -s, -r, or -g. Argument: As-name string (alternative filename). When receiving files, this can be a directory name. |
-b arg | N | Speed for serial device. Equivalent to SET SPEED. |
C-Kermit has hundreds of commands, and they can be issued in infinite variety and combinations, including commands for:
- Making connections (SET LINE, DIAL, TELNET, SSH, FTP, CONNECT, ...)
- Breaking connections (HANGUP, CLOSE)
- Transferring files (SEND, GET, RECEIVE, MOVE, RESEND, ...)
- Establishing preferences (SET)
- Displaying preferences (SHOW)
- Managing local files (CD, DELETE, MKDIR, DIRECTORY, RENAME, TYPE, COPY, TOUCH, ...)
- Managing remote files (RCD, RDEL, RMKDIR, RDIR, ...)
- Using local files (FOPEN, FCLOSE, FREAD, FWRITE)
- Programming (TAKE, DEFINE, IF, FOR, WHILE, SWITCH, DECLARE, ...)
- Interacting with the user (ECHO, ASK, ...)
- Interacting with a remote computer (INPUT, OUTPUT, ...)
- Interacting with local programs (RUN, EXEC, PTY, ...)
- Logging things (LOG SESSION, LOG PACKETS, LOG DEBUG, ...)
- And of course QUIT or EXIT to get out
- HELP to get help,
- and for programmers:
- variables, arrays, associative arrays, integer and floating point arithmetic,
- loops, decision making,
- macros, built-in and user-defined functions, string manipulation, pattern matching, block structure, scoping, recursion, and all the rest.
- To get a list of all C-Kermit's commands, type a question mark (?) at the prompt.
- To get a description of any command, type HELP followed by the name of the command, for example:
help send
- The command interruption character is Ctrl-C (hold down the Ctrl key and press the C key).
- The command language "escape character" is backslash (), used to introduce variable names, function invocations, and so on. If you need to include a literal backslash in a command, type two of them, e.g.:
get c:\\k95\\k95custom.ini
. It also introduces variable names and calls to built-in functions.