CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   I want OpenFOAM to email me when it's done, is this too much to ask?!? (https://www.cfd-online.com/Forums/openfoam-post-processing/117621-i-want-openfoam-email-me-when-its-done-too-much-ask.html)

JR22 May 12, 2013 04:30

I want OpenFOAM to email me when it's done, is this too much to ask?!?
 
Hi,

Is it possible to have the computer where your model is running send you an email (text message, or whatever) when either the model finished running, or when it breaks due to an error? I have a desktop computer running my OpenFoam models, and it sometimes takes minutes (when the model breaks) or hours (when the model successfully runs).

Thanks

P.D. I realize this might be more of a Linux than an OpenFoam question, but I bet it is very relevant to modeling.

wyldckat May 12, 2013 06:45

Hi Jose,

Well, it all depends on how you ran the case in the first place... if you used an Allrun script, identical to OpenFOAM's tutorials, then you can try adding this to the end of the script:
Code:

echo "Sending separate email with the simulation status..."
  (
    echo "Case in question:"
    head -n 20 log.$application
    echo
    echo
    echo
    echo
    echo "Last 100 lines of the output for the solver $application:"
    echo
    tail -n 100 log.$application
  ) | mail -s "Summary Report from the case $PWD" yourname@email.address

The mail application can be one of several. In my case, I use the package "bsd-mailx" on Ubuntu.

The "$application" variable is sometimes defined in Allrun scripts... for example in "tutorials/incompressible/pimpleFoam/TJunctionFan/Allrun": https://github.com/OpenFOAM/OpenFOAM...tionFan/Allrun

Best regards,
Bruno

Lieven May 12, 2013 12:03

Just as an addition.
If the system you run the jobs on is working with a resource management system like PBS/Torque, you can add something like
Code:

#PBS -m ae -M albert.einstein@princeton.edu
to the run script...

Cheers,

L

olivierG May 13, 2013 09:26

hello,

You may also take a look at the function Object "systemCall", which should also work.

regards,
olivier

wyldckat May 13, 2013 17:30

Greetings to all!

@Olivier: Nice one! But the downside of the "systemCall" is that it will only work if all goes well...

By the way, for anyone who is intrigued by the "systemCall" function object: http://openfoamwiki.net/index.php/Ti...ect_systemCall

Best regards,
Bruno

gschaider May 15, 2013 17:45

Quote:

Originally Posted by JR22 (Post 426970)
Hi,

Is it possible to have the computer where your model is running send you an email (text message, or whatever) when either the model finished running, or when it breaks due to an error? I have a desktop computer running my OpenFoam models, and it sometimes takes minutes (when the model breaks) or hours (when the model successfully runs).

Thanks

P.D. I realize this might be more of a Linux than an OpenFoam question, but I bet it is very relevant to modeling.

The most failsafe method to get a message even if the run fails is to call the solver from wrapper-script. That script would capture the output of the run and mail the last 100 lines or so to you (like PBS somebody mentioned further down)

That was the objective part. Here comes the advertisement:

I implemented a general framework for that in pyFoam (in the runner-utilities to be concrete). If a solver started with one of these utilities stops a number of postRunHooks (which are configured by the user in sections that start with the name postRunHook) are run. Currently the concrete hooks that are implemented are
- recording the run in a SQLite database
- contacting a webservice at a specific URL and send some information
The second one I use regularly. It contacts https://pushover.net and that service sends a message to my phone (which case, whether it ended OK etc). The configuration for that (minus my username and the API-key ;) ) is part of the distribution of pyFoam (you'd just have to insert your username/key and set it to enabled) as an example: it is templatable so any similar webservice could be used. Ah. And BTW: this only sends messages if the run took longer than X seconds. That way my phone doesn't get spammed with runs that don't get past the first timestep

Mails could work with these Hooks too, but I haven't had the need for that yet so that is not yet implemented

PS: to use pushover you don't have to use pyFoam. That can be easily accessed from shell-scripts too

immortality August 30, 2013 06:38

1 Attachment(s)
Quote:

Originally Posted by wyldckat (Post 426987)
Hi Jose,

Well, it all depends on how you ran the case in the first place... if you used an Allrun script, identical to OpenFOAM's tutorials, then you can try adding this to the end of the script:
Code:

echo "Sending separate email with the simulation status..."
  (
    echo "Case in question:"
    head -n 20 log.$application
    echo
    echo
    echo
    echo
    echo "Last 100 lines of the output for the solver $application:"
    echo
    tail -n 100 log.$application
  ) | mail -s "Summary Report from the case $PWD" yourname@email.address

The mail application can be one of several. In my case, I use the package "bsd-mailx" on Ubuntu.

The "$application" variable is sometimes defined in Allrun scripts... for example in "tutorials/incompressible/pimpleFoam/TJunctionFan/Allrun": https://github.com/OpenFOAM/OpenFOAM...tionFan/Allrun

Best regards,
Bruno

Hi Bruno
I use a script that have set its address in bashrc,how to add this code to that script?
and how to use bsd-mailx?

wyldckat August 31, 2013 12:24

Hi Ehsan,

Quote:

Originally Posted by immortality (Post 448877)
I use a script that have set its address in bashrc,how to add this code to that script?

Replace:
Code:

yourname@email.address
with your variable, such as:
Code:

$MY_EMAIL_ADDRESS
I'm assuming of course that you are talking about "~/.bashrc" and that you have a line like this inside it:
Code:

export MY_EMAIL_ADDRESS=yourname@email.address
Quote:

Originally Posted by immortality (Post 448877)
and how to use bsd-mailx?

Code:

sudo apt-get install bsd-mailx
Best regards,
Bruno

immortality September 4, 2013 07:28

Hi Bruno
I use this script as you mentioned:
Code:

#!/bin/bash
solver=$2
pyFoamPlotRunner.py --hardcopy --non-persist --with-deltat --with-courant --report-usage --report-analyzed-data --procnr=$1 $solver
application=`getApplication`
echo "Sending separate email with the simulation status..."
  (
    echo "Case in question:"
    head -n 20 log.$application
    echo
    echo
    echo
    echo
    echo "Last 100 lines of the output for the solver $application:"
    echo
    tail -n 100 log.$application
  ) | mail -s "Summary Report from the case $PWD" $MY_EMAIL_ADDRESS
shutdown -h +5

but sending email didn't performed,but this error:
Code:

/home/ehsan/Desktop/codes/runPlot: line 4: getApplication: command not found
Sending separate email with the simulation status...
head: cannot open `log.' for reading: No such file or directory
tail: cannot open `log.' for reading: No such file or directory

what files should be use instead of log files?

I found this file containing a log of solution:PyFoamRunner.rhoCentralFoamGasCont.logfil e
how can I put it in the code such that the solver read from controlDict instead of explicitly assigned?and why get Application didn't work?

pbachant September 4, 2013 15:01

I have my cases set up to run a Python script that emails me when a simulation finishes. See http://petebachant.me/automatic-email-openfoam/ for the code I used. I also put lines in the Allrun.pre and Allrun scripts to send desktop notifications when meshing or simulations finish. Example:

Code:

notify-send "OpenFOAM" "Meshing finished."

immortality September 4, 2013 15:48

Thanks a lot,how can make it send SMS?
this link is unfortunately banned here,could you please send me the required texts?
http://alextrle.blogspot.com/2011/05...th-python.html

pbachant September 4, 2013 15:52

Quote:

Originally Posted by immortality (Post 449926)
Thanks a lot,how can make it send SMS?
this link is unfortunately banned here,could you please send me the required texts?
http://alextrle.blogspot.com/2011/05...th-python.html

You essentially need to find your mobile provider's SMS gateway and send an email there. First figure out how to send an SMS to your phone via email, and adapt the code to send to that email address. Here's a Wikipedia article that may help:

http://en.wikipedia.org/wiki/List_of_SMS_gateways

wyldckat September 4, 2013 16:13

Greetings to all!

@Ehsan: That's what happens when you don't use the convention used in OpenFOAM's tutorials.
An example that can be used in the tutorials is this:
Code:

#!/bin/sh
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

application=`getApplication`
runApplication blockMesh
runApplication $application

The "getApplication" function only works when the "RunFunctions" script is sourced.
The "runApplication" function will run the application indicated by "getApplication" and will automatically log the output inside the file "log.$application".

Best regards,
Bruno

immortality September 4, 2013 16:43

Hi Bruno
but I was using pyFoam for run,which form is suitable for my case? although fortunately the runs are ended successfully.

wyldckat September 4, 2013 16:48

But... it's so simple to look at the code, compare with what I wrote, and fix it yourself!!
Instead of this:
Quote:

Originally Posted by immortality (Post 449806)
Code:

#!/bin/bash
solver=$2
pyFoamPlotRunner.py --hardcopy --non-persist --with-deltat --with-courant --report-usage --report-analyzed-data --procnr=$1 $solver
application=`getApplication`
echo "Sending separate email with the simulation status..."
  (
    echo "Case in question:"
    head -n 20 log.$application
    echo
    echo
    echo
    echo
    echo "Last 100 lines of the output for the solver $application:"
    echo
    tail -n 100 log.$application
  ) | mail -s "Summary Report from the case $PWD" $MY_EMAIL_ADDRESS
shutdown -h +5


Use this:
Code:

#!/bin/bash
solver=$2
pyFoamPlotRunner.py --hardcopy --non-persist --with-deltat --with-courant --report-usage --report-analyzed-data --procnr=$1 $solver
echo "Sending separate email with the simulation status..."
  (
    echo "Case in question:"
    head -n 20 PyFoamRunner.rhoCentralFoamGasCont.logfile
    echo
    echo
    echo
    echo
    echo "Last 100 lines of the output for the solver $solver:"
    echo
    tail -n 100 PyFoamRunner.rhoCentralFoamGasCont.logfile
  ) | mail -s "Summary Report from the case $PWD" $MY_EMAIL_ADDRESS
shutdown -h +5

See? It's simple! :p

immortality September 4, 2013 17:15

dear Bruno
you know I wanted a more general form,but never mind,I'm engaging with making a lot of graphs now!

immortality September 4, 2013 17:24

Dear Bruno I performed a quick run while I've added this to .bashrc:
Code:

export MY_EMAIL_ADDRESS=force.of.love@gmail.com
and the message is happy:
Code:

End

Finalising parallel run

gnuplot> set terminal png small color
       
gnuplot> set terminal png small color
                                      ^
                line 0:    invalid color spec, must be xRRGGBB

      ^
        line 0: invalid color spec, must be xRRGGBB

Killing PID 5032
 PyFoam WARNING on line 232 of file /usr/local/lib/python2.7/dist-packages/PyFoam/Execution/FoamThread.py : Process 5032 was already dead

  Used Memory:  0.57421875 MB

gnuplot> set terminal png small color
                                ^
        line 0: invalid color spec, must be xRRGGBB

Sending separate email with the simulation status...

Broadcast message from ehsan@Ehsan-com
        (/dev/pts/2) at 1:44 ...

The system is going down for halt in 5 minutes!
shutdown: Shutdown cancelled

but OpenFOAM hasn't sent me an email!:(
it has forgotten me after one year being friend with me:( it doesn't send me even an email now!:D;)
how long it takes to send it?it should be interesting.:cool:
---------
it seems it hasn't read the file at all because the messages in block aren't shown,right Bruno?

wyldckat September 7, 2013 07:07

Hi Ehsan,

When dealing with programming, you should always test the code before using it in critical deployments.

Therefore, try running this from the command line:
Code:

echo "Testing emailing functionality" | mail -s "Summary Report from the case $PWD" $MY_EMAIL_ADDRESS
If this doesn't work, then you should ask about this specific problem elsewhere, since this isn't a problem specific to OpenFOAM related software, nor CFD related :(.

Best regards,
Bruno

immortality September 7, 2013 07:20

it doesn't complain about something but doesn't send an email.
Code:

ehsan@Ehsan-com:~$ echo "Testing emailing functionality" | mail -s "Summary Report from the case $PWD" $MY_EMAIL_ADDRESS
ehsan@Ehsan-com:~$


wyldckat September 7, 2013 07:42

Well, the only way I could get it to send emails was to send them to the machine I'm working one, like this:
Code:

echo "Testing emailing functionality" | mail -s "Summary Report from the case $PWD" $USER@localhost
Then the emails can be read by running:
Code:

mail
Anything else beyond this is clearly beyond the scope of this forum :(.


All times are GMT -4. The time now is 16:13.