Execute command and notify about failure via email
Go to file
2021-07-24 15:20:59 +02:00
.idea v0.1.0 2021-07-22 16:20:03 +02:00
etc/execNotify v0.0.2 2021-07-22 13:01:18 +02:00
src/de minor improvements 2021-07-24 15:20:59 +02:00
.gitignore v0.1.0 2021-07-22 16:20:03 +02:00
LICENSE Update 'LICENSE' 2021-04-20 10:10:10 +02:00
pyproject.toml v0.0.2 2021-07-22 13:01:18 +02:00
README.md Update 'README.md' 2021-07-24 12:19:56 +02:00
requirements.txt add "make install" and other fixes 2020-12-06 16:40:03 +01:00
setup.cfg v0.1.1 2021-07-22 17:11:23 +02:00

execNotify

Installation - venv

More detailed instructions about venv can be found at https://docs.python.org/3/library/venv.html

Create a venv:

python3 -m venv ~/execNotify/venv

Activate the venv:

source ~/execNotify/venv/bin/activate
# echo "VIRTUAL_ENV=${VIRTUAL_ENV}"

Option A: Install the module from TestPyPI:

python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps --upgrade de.p1st.exec-notify

The above command uses the parameter --no-deps:

Since TestPyPI doesnt have the same packages as the live PyPI, its possible that attempting to install dependencies may fail or install something unexpected. While this package doesnt have any dependencies, its a good practice to avoid installing dependencies when using TestPyPI.

Option B: Install from local directory

python3 -m pip install ~/Downloads/git/execNotify/

(Optionally) list installed modules:

pip list

Instalation - global

sudo python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps --upgrade de.p1st.exec-notify

Configuration

Create configuration file /etc/execNotify/cfg.ini.

For the required fields, see ./etc/execNotify/cfg.ini.example

Usage

Usage of execNotify

Add de-p1st-execNotify in front of your command to execute.

You can pipe into de-p1st-execNotify but not from de-p1st-execNotify as the output gets modified.

Example:

de-p1st-execNotify ls /non/existent/file will mail you the exit code, stdout and stderr of ls /non/existent/file

Usage of notify

Send stdout via mail:

echo "Hello world!" | de-p1st-notify

Send stdout and stderr via mail:

echo "Hello world!" 2>&1 | de-p1st-notify

Send stdout and specify an optional email subject:

echo "Hello world!" | de-p1st-notify "someSubject"

Send message without using a pipe:

de-p1st-notify "someSubject" "Hello World! What's up?"

Development

When started with environment variable DE_P1ST_EXEC_NOTIFY set, then the configuration file is read from ./etc/execNotify/cfg.ini.

Testing

See heading "Installation" above with steps to locally install this module.

Uploading to TestPyPI

More detailed instructions can be found at https://packaging.python.org/tutorials/packaging-projects/

  1. Set up a venv
  2. Increase/Adjust [metadata][version] in setup.cfg
  3. Install the build and twine modules to your venv.
  4. Next generate a distribution archive:
python3 -m build
  1. Upload the distribution packages with twine. For the username, use __token__. For the password, use a test.pypi.org API token:
python3 -m twine upload --repository testpypi dist/*
  1. Congratulations! You can view the uploaded module under: