Results 1 to 4 of 4

Thread: Notification email sent before a job is done

  1. #1
    Join Date
    Apr 2011
    Beans
    3

    Question Notification email sent before a job is done

    Hi, I searched the internet and use the following script to send a notification email when a R program is done. However, I found that it always sends me email immediately even when R is still running. Is there anything wrong in this script? Thanks.

    Code:
    #!/bin/sh
    clear
    R CMD BATCH --vanilla ./Programs/ranktest20110415.R ./Programs/ranktest20110415.log &
    ssmtp xxx@me.com < jobdone.txt
    Last edited by lisati; April 17th, 2011 at 01:39 AM. Reason: Add code tags

  2. #2
    Join Date
    Jun 2007
    Location
    Paraparaumu, New Zealand
    Beans
    Hidden!

    Re: Notification email sent before a job is done

    When you put the & at the end of the line, the command is "backgrounded", and the script keeps on running without waiting for the program to finish.
    Forum DOs and DON'Ts
    Please use CODE tags
    Including your email address in a post is not recommended
    My Blog

  3. #3
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: Notification email sent before a job is done

    You need two ampersands ("&&") which is a logical connector in bash. The sequence

    Code:
    command1 && command2
    runs command2 only if command1 completes successfully.

    With only one ampersand, the first command is run in the background as lisati notes, then the second command is run regardless of the outcome of the first command.

  4. #4
    Join Date
    Apr 2011
    Beans
    3

    Re: Notification email sent before a job is done

    Thank you, lisati and SeijiSensei. It helps alot.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •