If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to notify when the process is completed in unix

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-08-09, 05:09
shijoe shijoe is offline
Registered User
 
Join Date: Mar 2009
Posts: 13
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
Reply With Quote
  #2 (permalink)  
Old 06-08-09, 05:54
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
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
Reply With Quote
  #3 (permalink)  
Old 06-10-09, 02:58
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,258
Like Mike said just mail the output from your script e.g.
myjob.sh | tee myjob.log | mailx -s 'myjob.log' myteam@myoffice.com &
Reply With Quote
  #4 (permalink)  
Old 06-10-09, 05:14
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
If they haven't said thank you after this amount of time then it's probably not worth helping them any more.
Reply With Quote
  #5 (permalink)  
Old 06-10-09, 05:49
shijoe shijoe is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 06-10-09, 05:50
shijoe shijoe is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 06-10-09, 09:13
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
  #8 (permalink)  
Old 06-19-09, 03:34
AnanthaP AnanthaP is offline
Registered User
 
Join Date: May 2009
Location: India
Posts: 62
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
Reply With Quote
  #9 (permalink)  
Old 06-29-09, 10:58
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On