How can I send a notification for a job, when it terminates?

1

I am working on a Linux system and I have been able to find solutions in the case where it will send a response for success or failure. But, in my case I need to know which one it is and I am often unable to check the machine itself until much later. So I was hoping that I could send an email from the command line for failure or success, containing information as to which of the two ended the calculations.

I have noted the question, “How can I trigger a notification when a job/process ends?” But, it doesn’t provide this duality condition.

Patrick Payne

Posted 2016-06-07T23:27:19.620

Reputation: 13

What happens for your "failure" case? non-zero exit status? message written to stdout/err? – glenn jackman – 2016-06-08T12:24:17.143

Answers

0

If you are on a linux system, a simple way to do this would be to pipe the output of the job (STDERR + STDOUT) into the standard linux mail program, mailx.

Here is an example of the code to do such a thing, using a SMTP relay:

/path/to/script arg1 arg2 2>&1 | mailx -E -s "SUBJECT" -S smtp=smtp://smtphostname -S from="calculation@servername" my@emailserver.com

spaceman spiff

Posted 2016-06-07T23:27:19.620

Reputation: 16

1May be adding a result of the script: if ! /path/to/script arg1 arg2 2>&1; then echo "FAILED"; fi | ... – Martian – 2016-06-08T10:43:27.900