Purpose
This article outlines the process for running a custom command that is external tocmsh
.
External to cmsh
If the custom command is an executable from the main operating system shell (bash usually), it can be run in cmsh
by prepending an exclamation point “!”.
For example, suppose there is a hypothetical bash script called “listusernamesfromexcel”. When this script is run, it provides a daily listing of new users to be added to the cluster. The script could handily be accessed in cmsh
with an “!” prefix:
% !listusernamesfromexcel
The “!” runs the command it prefixes in a subshell. (“!” on its own opens up the subshell).
Aliasing Commands
If the script is used frequently, it may be worthwhile to create an alias in bash (or .bashrc or .bash_profile for permanence) to something shorter for convenience, such as “lunfe”. This will allow the command to be reduced to:
% !lunfe
If the “!” character is inconvenient, the (external) script can also be aliased in cmsh
. The current way to do this is to create a <command>.cmsh file with the contents of the file being the command.
<command>.cmsh
In this example, you could create a file lunfe.cmsh
with !lunfe
as its content. Then, after restarting cmsh
, it is possible to run the command lunfe without using ‘!’. That is, as:
% lunfe
Internal to cmsh
Within cmsh
we can alias commonly used commands, and we do not have to use the exclamation point “!” character, as we are not accessing the subshell.
Within the restrictions of using cmsh commands only, an alias such as the following can be set to create the alias “dum
” for the longer device use master
:
% alias dum device use master
This alias can be made permanent by adding it to ~/.cm/cmsh/.cmshrc.
The .cmshrc dotfiles can be in these paths, with priority order as follows (ie: shortest path first):
~/.cmshrc.
~/.cm/.cmshrc.
~/.cm/cmsh/.cmshrc.
The <command>.cmsh files have corresponding priorities.
Extreme customization
cmsh
is a fine tool, but it isn’t a scripting language – it’s just a front end for CMDaemon. Fortunately, there are Python API bindings for CMDaemon which may suit your needs. For more information, please refer to Chapter 1 of the developer manual.