The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
background jobs exit status and limit the number of jobs to run GrepMe Shell Programming and Scripting 1 06-11-2007 07:56 PM
background job finished notification nkeller UNIX for Dummies Questions & Answers 4 03-08-2007 12:41 PM
Background jobs Jeremiorama High Level Programming 1 11-25-2005 09:48 AM
Checking background jobs from another session vikingshelmut UNIX for Dummies Questions & Answers 3 10-12-2005 06:34 PM
background jobs qsi Shell Programming and Scripting 4 11-24-2004 05:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2007
vibhor_agarwali vibhor_agarwali is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 259
Notification from Background jobs

Reposting, as it got lost during the database backup.

Via a shell script a spawn 3 background jobs namely a, b & c.

These will take different times to complete.

I want to print a different message on completion of each.

How can i find out when each one has completed independently.

Thanks
  #2 (permalink)  
Old 06-18-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Create a wrapper script for each task that prints the message when the wrapper completes. Then have the main script spawn each wrapper instead.
  #3 (permalink)  
Old 06-18-2007
vibhor_agarwali vibhor_agarwali is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 259
Wrapper script
  #4 (permalink)  
Old 06-18-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Hi,
Does this approach helps?.

Gurus,
Please provide suggestions.


Code:
#!/bin/ksh
LOG_FILE=/tmp/${0##*/}.log

LogMsg() {
 print "$(date +%d/%m/%y:%H:%M:%S) : $@"  >> $LOG_FILE
}

CallA() {
 LogMsg "Calling Function A"
 iostat 5 5  >> $LOG_FILE &
 wait $!
 LogMsg "A done with $!"
 return 45
}

CallB() {
 LogMsg "Calling Function B"
 vmstat 5 5  >> $LOG_FILE &
 wait $!
 LogMsg "B done with $!"
 return 46
}

Main() {
 LogMsg "Starting the Process - Main"
 CallA
 Ret=$?
 LogMsg " Returned value $Ret "
 CallB
 Ret=$?
 LogMsg " Returned value $Ret "
}

# Call the Main Function here
Main


Thanks
Nagarajan Ganesan
  #5 (permalink)  
Old 06-18-2007
vibhor_agarwali vibhor_agarwali is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 259
But on calling CallA, the control won't return to Main till it ends, as wait ?! will wait for it.

I have to spawn all things simultaneously.

BTW what's
${0##*/}
  #6 (permalink)  
Old 06-18-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
why cant you...

start A
start B
start C
wait

where each of A, B and C do the following

print a line saying they have started
run the task
print a line saying they have ended
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0