SYNOPSISshush [ -h | -V ]
shush [ -c dir ] [ -S | -s facility ] [ -vfmk ] name [ ID ]
shush [ -c dir ] [ -H to ] [ -R to ] [ -T to ] -C name [ stdout [ stderr ] ]
shush [ -i | -u | -r ] [ -c dir ]
DESCRIPTIONshush runs a command and optionally reports its output by mail. It is a useful wrapper around cron jobs. By default, shush will not produce any output when running as everything (if anything) is reported by mail. However, configuration as well as critical errors will be reported on the standard error and (optionally) syslog. Because interrupting shush has dire consequences including the likely loss of any output from the command, the following commonly used signals are ignored by shush: SIGHUP, SIGINT, SIGQUIT and SIGTERM. If one really wants to kill a running instance of shush rather than killing the running managed command, SIGKILL may be used and shall serve as a reminder of how inappropriate such action typically is.
For a command to be run using shush, a configuration file name must exist in the configuration directory ($HOME/.shush by default). This file defines how the command should be run as well when to send reports by mail. For details on available configuration parameters, see the CONFIGURATION section below.
Two additional configuration files may exist: name.stdout and name.stderr (by default). These files are used to look at the standard output and standard error (respectively) produced by the command. For details on how to use these, see the COMMAND OUTPUT section below.
When the -C option is specified, shush will only load the configuration, optionally analyze the standard output and standard error from the specified files and finally produce sample reports if desired. This may also be used to produce reports if shush failed to properly terminate when running a command. (The standard output and error from the command are normally found in files located under /tmp.)
shush is able to manage crontab(5) entries based on configurations defined by the user. This may be done in one of two ways. If a file named "schedule" exists in the configuration directory, then it is read for scheduling information. Each line should contain a single entry containing three fields separated by whitespace(s). The fields are (in order) the hostname for which the entry applies or the character "*" to include all hosts, the configuration name, and finally, the scheduling information in the same format as is used by the schedule parameter (see below). To specify an ID, use name:ID as the second field. If there is no file named "schedule", then shush checks the configuration directory for configuration files and adds them to the current user's crontab(5) file as specified by the included schedule parameter (see below). Files whose names start with the character "#" or end with the character "~" are ignored.
- Display a brief help message.
- Display the version information. Prefix with -v to display compile time defaults.
- -c dir
- Specify the directory where configurations are stored.
- -s facility
- Defines the syslog facility to use for logging.
- Disable syslog logging.
- Copy information log messages to the standard output.
- Fast mode: Any configured randomdelay is ignored.
- Monitor and display the command's standard output and error in real time.
- Keep the command's output log files instead of deleting them upon completion.
- Check the configuration without running any command.
- -H to
- Send a sample HTML report to the specified recipient(s).
- -R to
- Send a sample enriched report to the specified recipient(s).
- -T to
- Send a sample text report to the specified recipient(s).
- Use crontab(1) to install a new crontab(5) file for the current user. The user must not already have a crontab(5) file.
- Use crontab(1) to update the current user's crontab(5) file, which must already exist.
Remove any entry added by the -u option from the current user's
CONFIGURATIONshush configuration files consist of a main section, report section(s) and parameters. The main section defines global parameters as well as defaults for reports. Each report section begins with the name of the report between brackets. Lines beginning with the character "#" are ignored. Parameters should be specified only once. If specified multiple times, all but the last occurrence will be ignored, unless noted otherwise. Parameters are defined using the following syntax:
The following parameters may appear in the main section:
- The actual command to run. shush sets two environment variables before running the command: SHUSH_NAME is set to name, and SHUSH_ID is set to ID.
- This defaults to the full path of the main configuration file. The other two configuration file names are obtained by appending the ".stdout" and ".stderr" suffixes to the value of this parameter.
- If set, this parameter instructs shush to obtain a lock file before running the command, and defines the actions to take in case the lockfile is held by another process. The format is a comma separated list of actions. Valid actions are: a time duration (during which shush should simply wait and keep trying to obtain the lockfile), the string "abort" (indicating that shush should terminate immediately if the lockfile already exists), the string "ignore" (indicating that shush should ignore an existing lockfile), the string "loop" (to mark where to start again from when all actions have been executed) and the string "notify=" followed by mail addresses to which a notification mail should be sent. Actions are executed in the order they are provided, and shush will wait forever trying to obtain the lockfile once all the actions have been executed, unless the string "loop" is one of defined actions. Time durations may be specified in units of w(eeks), d(ays), h(ours), m(inutes) or s(econds). If no unit is specified, it is assumed to be minutes.
- By default, shush will use a file located in the same directory as the configuration file, and named after the configuration and host names. An alternate filename may be specified using this parameter.
- If set, this string will be used as subject for lock notification(s) mail messages. The default is "[%[email protected]%h] **PENDING** %N [%t]". See the MAIL SUBJECT section for details on the format.
- shush does not modify the environment, except to set the PATH variable if the path parameter is set.
- If this parameter is set, shush will wait up to the specified amount of time before starting the command unless invoked with the -f. Valid time units are: s(econds), m(inutes), h(ours), d(ays), w(eeks). If no unit is specified, it is assumed to be minutes.
- This defines when to run this command as a cron job, in a crontab(5) compatible format. Multiple entries may be specified using the character ";" as separator. Entries prefixed by the character "#" will be skipped. This parameter is not directly used by shush to run the command, but used by the -i and -u options.
- This may be used to override the command used to send mail.
- By default, the Bourne shell sh(1) is used to run the command, allowing any shell syntax to be used. An alternate shell may be defined using this parameter.
- This defines the directory where the status of shush is saved and defaults to the ".state" directory under where the configuration is located. An error is generated if the directory does not exist unless this option was not set. Setting this option to an empty string will prevent shush from saving its status. shlast(1) uses these state files to report on running instances of shush as well as previous runs.
- This parameter is only used by the -i and -u options and has no other effect on shush. It allows overriding the default syslog facility used for logging and defined at compile time. If left blank, this suppresses the use of syslog.
- This parameter allows one to control how long the command may run. It should be a comma separated list of actions. Valid actions are: a time duration (during which shush should simply wait for the command to terminate), a signal (either "SIGNAME" or "-SIGNUMBER") that should be sent to the command's process group, a signal (either "=SIGNAME" or "=SIGNUMBER") that should be sent to the shell used to spawn the command, the string "loop" (to mark where to start again from when all actions have been executed) and the string "notify=" followed by mail addresses to which a notification mail should be sent. Actions are executed in the order they are provided, and shush will wait forever if the command is still running once all the actions have been executed unless the string "loop" is one of defined actions. Time durations may be specified in units of w(eeks), d(ays), h(ours), m(inutes) or s(econds). If no unit is specified, it is assumed to be minutes.
- If set, this string will be used as subject for timeout notification(s) mail messages. The default is "[%[email protected]%h] **TIMEOUT** %N [%t]". See the MAIL SUBJECT section for details on the format.
The following parameters may appear anywhere in the configuration. If specified in the main section, they define defaults settings that will apply to any report for which the same parameter has not been defined.
- to, cc, bcc
- Where to send the mail report.
- Subject of the mail report. See the MAIL SUBJECT section for details on the format.
- Additional mail header(s). Note that this parameter may be repeated to specify multiple headers. However, only headers from the report (if specified) or from the main section will be used for a given report.
- By default, specified subjects are prefixed with the host name between brackets. This parameter allows one to customize this prefix. A positive integer indicates how many components of the fully qualified hostname should be shown. A negative integer indicates how many trailing components of the fully qualified hostname should be trimmed. The integer zero indicates that the prefix should be omitted. This parameter is ignored if the "subject" contains any "%" character.
- By default, specified subjects are prefixed with the username between brackets. This parameter allows one to disable this prefix. Any non zero value indicates that the username should be shown while zero causes the prefix to be omitted. This parameter is ignored if the "subject" contains any "%" character.
This defines how the command's standard output and standard error are captured and reported to the user: "errfirst", "mixed", "outfirst". When using "mixed", the name.stderr configuration file is ignored. When using "errfirst" or "outfirst", individual reports may use one of the following two additional options "outonly" and "erronly".
- Mail messages sending the output of the command may be sent in three different formats: "text" (the default), "enriched" text or "html".
- By default, the entire output of the command is sent in mail reports. This parameter may be used to limit the size of the output included in a report. Note that the total size of mail sent will be greater as this limit has no effect upon mail headers. The size can be specified in units of m, k, b, c (MB, KB, Bytes). If no unit is specified, it is assumed to be KB. A limit of zero indicates that the output should not be truncated.
A report is only sent if no if condition is specified or if the
specified if condition is true. The condition syntax allows for the
usual logical operators ("||", "&&", "!"), comparison operators ("==",
"!=", "<", "<=", ">", ">=") and basic arithmetic operators ("+", "-").
Aside from counters defined by the configuration (see the COMMAND
OUTPUT section below), the following variables may be used:
- If the command terminated normally, this is its exit code. Otherwise, it is negative and indicates the signal number having caused the command to terminate (e.g. -1 indicates signal number 1 caused the command to terminate).
- output size (in bytes), same as "$outsize + $errsize"
- size (in bytes) of standard output
- size (in bytes) of standard error
- number of lines output
- number of standard output lines
- number of standard error lines
- command run time (in seconds)
- user time used by the command
- system time used by the command
1 if shush is run from a terminal (e.g. interactively), 0 otherwise.
MAIL SUBJECTSThe "lockmsg", "timeoutmsg" and "subject" parameters may contain the following tokens which are expanded as described below:
- The "%" character
- The hostname
A partial hostname: A positive digit indicates how many components of the fully qualified hostname to keep; a negative digit indicates how many trailing components of the fully qualified hostname to trim.
- The instance ID
- The configuration name
- The configuration name and instance ID
- The report name
- The elapsed time.
- The username.
If the "%" character is found in the "subject" parameter, then the "hostprefix" and "userprefix" parameters are ignored.
COMMAND OUTPUTAfter the command terminates, shush will use the contents of the name.stdout and name.stderr files (if they exist) to look at the output produced by the command.
These files follow a simple format. Each line is composed of a single character (the counter name) followed by a regular expression.
All counters are initialized to 0 (zero). Each line of output is matched against these regular expressions until a match is found. If a match is found, the associated counter is incremented by one. These counters may then be used as part of the main configuration, in an "if" configuration parameter, allowing the decision to send a mail report to be based on how many times certain regular expressions have been matched.
Finally, regular expressions may define sub-expressions which will be rendered in bold in mail reports.
Lines starting with the character "#" are considered to be comments and are ignored. By default, standard regular expressions are used, unless the first line is "#pcre" in which case Perl compatible regular expressions are used.
If the -c option is not used, shush will look for configuration
files in $HOME/.shush.
If defined, this should point to the sendmail(1) binary. This
variable overrides the "sendmail" configuration setting and should be
used with care.
Directory where temporary files are created.
EXAMPLEThe following configuration runs "shush -c /etc/shush -u" daily at 9:00, updating the user (root) crontab:
command=shush -c /etc/shush -u schedule=0 9 * * * lock=notify=root root-logs,abort timeout=5m,loop,notify=root root-logs,15m stderr=first format=text Subject=Crontab Daily Update [logs] to=root-logs [readers] if=$exit != 0 || $outlines != 1 || $errsize > 0 || U to=root format=rich
The associated configuration for standard output is:
Oshush: crontab updated\.$ U^.+$
and for standard error:
A lock will be set while running the command, and mail sent to "root" and "root-logs" if the lock is held by another process when shush starts, in which case shush will abort. A mail will also be sent to "root" and "root-logs" if "shush -c /etc/shush -u" runs for more than 5 minutes, and for every 15 minutes following the first 5 minutes.
Upon completion, the output will always be sent to "root-logs". Additionally, the output will be sent to "root" if the condition "$exit != 0 || $outlines != 1 || $errsize > 0 || U" is true. For this condition to be true, one of the following must be true: the exit code is non zero, the command standard output was not a single line, there was output on standard error or finally, the counter "U" is non zero. For the counter "U" to be non zero, there must be output on standard output other than the line "shush: crontab updated.". Finally, any line of output produced on the standard error will be displayed in bold in mails sent to "root".
AVAILABILITYThe latest official release of shush is available on the web. The home page is http://web.taranis.org/shush/
AUTHORChristophe Kalt <[email protected]>
BUGSThe -C option does not allow specifying an ID.
For other bugs, send reports to `[email protected]'.