Next: , Previous: , Up: GNUN Scripts   [Contents][Index]


6.2.10 The mailfail Script

This is a helper script that runs a command, and mails the output of that command in case it exits with a non-zero exit status. mailfail depends on GNU Mailutils, or a compatible implementation, such as BSD’s mailx.

Usage:

mailfail [--dry-run] RCPT SUBJECT CMD [ARG ...]

The mailfail script accepts the following options:

--dry-run

Does not send the email message.

RCPT

The recipient of the message in a valid format, like [email protected].

SUBJECT

The subject of the message; if it is longer than a word you should guard it with quotes.

CMD

The command you want to run and send a mail in case it fails.

ARG…

The arguments of CMD, if any.

Here is a typical example, similar to the way it is used in GNUN:

mailfail [email protected] "Bad PO" msgfmt -cv -o /dev/null bg.po

This will check the validity of bg.po with the msgfmt program and in case there are errors, a message will be sent to the specified address with ‘Bad PO’ as subject and the error output from msgfmt as body.

mailfail inherits the exit status of the command being run. If an argument is missing, the usage information is printed to the standard output and the exit code is 1.