Is there a program that can send me a notification e-mail when a process finishes?
Yeah, there is
command; echo "Process done" | mail -s "Process done" [email protected]
Where -s "text" is the subject, the echo gives mail some Text to send to you.
Jobs submitted to the at
daemon will send any output to you from stderr and stdout upon completion. It can also be configured to send mail even if the job has no output. It also has the benefit of running without a controlling terminal, so you don't have to worry about the effect that closing your terminal will have on the job.
example:
echo "/opt/product/bin/job.sh data123"|at -m NOW
When this job completes, the user who submitted the job will receive an email, and if there is any output at all you will receive it. You can change the email recipient by changing the LOGNAME
environment variable.
at
has a batch mode where you can queue jobs to run when the system is not busy. This is not a very good queueing system when multiple users are competing for resources, but nonetheless, if you wanted to run jobs with it:
echo "/opt/product/bin/job.sh dataA"|batch
echo "/opt/product/bin/job.sh dataB"|batch
echo "/opt/product/bin/job.sh dataC"|batch
By default the jobs will not start unless the system load is under 1.5, but that load figure can be adjusted (and with 24 cores I'd say you should). They can run in parallel if they don't bump the loadavg over the load limit (1.5 default again), or if they individually bump the loadavg over 1.5, they will run in serial.
You can view the job queue with atq
, and delete jobs with atrm
Answer dependencies:
- Running
atd
daemon (ps -ef|grep atd
) - You are allowed to submit jobs to
atd
(not denied by/etc/at.deny
//etc/at.allow
configurations) - Functional
sendmail
MTA
Most systems have no problem with these requirements, but it's worthwhile to check.
I would recommend setting a python script to send an email, they are very easy to write and configure the correct mailing servers for whatever service you use. They look something like this:
#!/usr/bin/python
import smtplib
sender = '[email protected]'
receivers = ['[email protected]']
message = """From: From Person <[email protected]>
To: To Person <[email protected]>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
Use this in conjunction with the pipe operator suggested in the other answers.
Another great solution I have found to this problem is using Pushover. Pushover - "Pushover makes it easy to send real-time notifications to your Android and iOS devices." I setup a simple script which ultised the easy API to send a message to my phone when my builds are done.
curl -s \
-F "token=APP_TOKEN" \
-F "user=USER_KEY" \
-F "message=The build is done." \
https://api.pushover.net/1/messages.json