Skip to main content

Daemonize a command and e-mail the results

Project description

Project Status: Active - The project has reached a stable, usable state and is being actively developed. CI Status https://codecov.io/gh/jwodder/daemail/branch/master/graph/badge.svg https://img.shields.io/pypi/pyversions/daemail.svg MIT License

GitHub | PyPI | Issues | Changelog

daemail (pronounced “DEE-mayl”, like “e-mail” but with a D) is a Python script built on top of python-daemon for running a normally-foreground command in the background and e-mailing its output (by default, the combined stdout and stderr) once it’s done.

Installation

daemail requires Python 3.6 or higher. Just use pip for Python 3 (You have pip, right?) to install daemail and its dependencies:

python3 -m pip install daemail

Usage

daemail [<options>] <command> [<arg> ...]

daemail runs command with the given arguments in the background and sends an e-mail once the command finishes. The sending of the e-mail is performed by the outgoing library, and thus an outgoing configuration file must be created with settings for sending e-mail before daemail can be used.

Options

-c FILE, --config FILE

Read sending configuration for the outgoing library from FILE; defaults to outgoing’s default configuration file

-C DIR, --chdir DIR

Change to DIR after daemonizing but before running the command; defaults to the current directory

-D MBOX, --dead-letter MBOX

If an error occurs when trying to send, append the e-mail (including a description of the error) to the file MBOX; defaults to dead.letter. If the file already exists, it must be a valid mbox file.

-e ENCODING, --encoding ENCODING

Expect the stdout (and stderr, if --split is not in effect) of the command to be in the given encoding; defaults to the preferred encoding returned by Python’s locale.getpreferredencoding. If decoding fails, the output will be attached to the e-mail as an application/octet-stream file named “stdout”.

When --mime-type or --stdout-filename is also given, this option has no effect other than to set the default value for --stderr-encoding.

-E ENCODING, --stderr-encoding ENCODING

Expect the stderr of the command to be in the given encoding; defaults to the value specified via --encoding or its default. If decoding fails, the stderr output will be attached to the e-mail as an application/octet-stream file named “stderr”.

This option only has an effect when --split is given, either implicitly or explicitly.

--foreground, --fg

Run everything in the foreground instead of daemonizing. Note that command output will still be captured rather than displayed.

-f ADDRESS, --from ADDRESS, --from-addr ADDRESS

Set the From: address of the e-mail. The address may be given in either the form “address@example.com” or “Real Name <address@example.com>.” If not specified, daemail will not set the From: header and will expect the mail command or SMTP server to do it instead.

-F, --failure-only

Only send an e-mail if the command failed to run or exited with a nonzero status

-l LOGFILE, --logfile LOGFILE

If an unexpected & unhandleable fatal error occurs after daemonization, append a report to LOGFILE; defaults to daemail.log

Such an error is a deficiency in the program; please report it!

-M MIME-TYPE, --mime-type MIME-TYPE, --mime MIME-TYPE

Attach the standard output of the command to the e-mail as an inline attachment with the given MIME type. The MIME type may include parameters, e.g., --mime-type "text/html; charset=utf-16". If --stdout-filename is not also supplied, the attachment is named “stdout”. Implies --split.

-n, --nonempty

Do not send an e-mail if the command exited successfully and both the command’s stdout & stderr were empty or not captured

--no-stdout

Don’t capture the command’s stdout; implies --split

--no-stderr

Don’t capture the command’s stderr; implies --split

-S, --split

Capture the command’s stdout and stderr separately rather than as a single stream

--stdout-filename FILENAME

Attach the standard output of the command to the e-mail as an inline attachment with the given filename. If --mime-type is not also supplied, the MIME type of the attachment is deduced from the file extension, falling back to application/octet-stream for unknown extensions. Implies --split.

-t ADDRESS, --to ADDRESS, --to-addr ADDRESS

Set the recipient of the e-mail. The address may be given in either the form “address@example.com” or “Real Name <address@example.com>.”

This option is required. It may be given multiple times in order to specify multiple recipients.

-Z, --utc

Show start & end times in UTC instead of local time

Caveats

  • Input cannot be piped to the command, as standard input is closed when daemonizing. If you really need to pass data on standard input, run a shell, e.g.:

    daemail bash -c 'command < file'

    or:

    daemail bash -c 'command | other-command'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

daemail-0.7.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

daemail-0.7.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file daemail-0.7.0.tar.gz.

File metadata

  • Download URL: daemail-0.7.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for daemail-0.7.0.tar.gz
Algorithm Hash digest
SHA256 517035ea7175e5adc0dd4e1310c43deda9de9b989ad67b0142adc18607c94632
MD5 349da9cbe6723a58c2080f604a22fac2
BLAKE2b-256 330219077191fa55da36644f455a32bca29ee654bffc61f2d32c0f0e1a8d0296

See more details on using hashes here.

File details

Details for the file daemail-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: daemail-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for daemail-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82c0526b0d4e7e85001569008f9e9ac3cf8324692ef0c6f1ad6e1c4a457b7c38
MD5 98fefcf338c0b526b46f41dbf4781fb7
BLAKE2b-256 62b713da13869d634d63a3d3222662ca288f21ebdf6e77e4ab9361e1ee543000

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page