Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2009
    Posts
    13

    Unanswered: How to notify when the process is completed in unix

    I have unix job.Once i start runnning the unix job. process number is generated and the job is running fine. I need to know when the job is completed.I need to write the script once the job or script is completed, it should shoot out the mail to team.Please provide some idea

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Quote Originally Posted by shijoe
    I have unix job.Once i start runnning the unix job. process number is generated and the job is running fine. I need to know when the job is completed.I need to write the script once the job or script is completed, it should shoot out the mail to team.Please provide some idea
    You should use the wait command ie
    Code:
    # start a background task that takes some time
    sleep 10 &
    
    # returns immediately with process id of background task
    
    # now wait for it to finish all background tasks
    wait
    but if it was me then I'd just alter the initial script so it mails your group when it finishes.

    Mike

  3. #3
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Like Mike said just mail the output from your script e.g.
    myjob.sh | tee myjob.log | mailx -s 'myjob.log' myteam@myoffice.com &

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    If they haven't said thank you after this amount of time then it's probably not worth helping them any more.

  5. #5
    Join Date
    Mar 2009
    Posts
    13
    Sorry for the dealay. I really appreciate your effort on this.

    If I start any process or script in unix. I will get the process number. To know the status of the process, we used the command ps -ef |grep process_number.
    Instead of doing this. We need to automate the process by send an auto mail once the job or process is completed.

    Thanks

    Shijoe

  6. #6
    Join Date
    Mar 2009
    Posts
    13
    We are writing every activities of job or script in the log. but we need to open the log and see the activity of script, wheather the script is completed or not.

    My expectation is simple. I just start run the unix script. It will take 3 to 4 hours to complete. Once the script is completed.I need to get a mail that so and so script is completed, please veryfy the logs...

    Once again I thank for all you folks

  7. #7
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool End of days...

    What did you NOT understand about Mike's and pdreyer's solution?

    Adding to those alternatives, you could just add code at the end of the script to e-mail the log:
    Code:
    #!/bin/ksh
    # this is myScript.sh
    #
    LOG_FILE=/path/to/logs/myScript.log
    #
    dosomething.sh >$LOG_FILE
    if [ $? -ne 0]
    then
      cat $LOG_FILE| mailx -s "$0 !ERROR, something happened." oper@mydomain.com
      exit 1
    fi
    #-- Etc --
    dosomethingelse.sh >>$LOG_FILE
    #-- Etc --
    # At end of the script add:
    cat $LOG_FILE| mailx -s "$0 All OK!" oper@mydomain.com
    exit 0
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  8. #8
    Join Date
    May 2009
    Location
    India
    Posts
    66
    shijoe.

    When the task is initiated, the process id gets known.

    I also understand that

    Now, write a loop that reads `ps` and greps for the process id. So long as the lines returned are > 0, then it is running.

    while
    do
    loop
    done
    cat logs | mail x ....
    The script needs to be refined to handle exceptions etc but is a fairly common text book example.

    End

  9. #9
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink Non-sensical

    Quote Originally Posted by AnanthaP
    shijoe.

    When the task is initiated, the process id gets known.

    I also understand that

    Now, write a loop that reads `ps` and greps for the process id. So long as the lines returned are > 0, then it is running.

    while
    do
    loop
    done
    cat logs | mail x ....
    The script needs to be refined to handle exceptions etc but is a fairly common text book example.

    End
    Yes, this script is nonsense. It should look more like Mike's, pdreyer's or my
    solution.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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