The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
exec to call specific function in C prog vpraveen84 UNIX for Advanced & Expert Users 2 06-03-2008 03:55 PM
alternatives of exec() system function Raj Kumar Arora High Level Programming 3 01-03-2008 02:27 AM
How to periodically execute a function in C ?? RipClaw High Level Programming 24 12-27-2007 12:19 AM
query about find and -exec shriashishpatil UNIX for Advanced & Expert Users 2 04-12-2007 02:16 AM
find and exec big123456 UNIX for Advanced & Expert Users 2 01-02-2006 12:10 PM

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 04-02-2007
piooooter piooooter is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 24
How can I execute own ksh function in find -exec

Hi,

I wrote a smiple ksh function

send_notification() {
...
}


and want to execute it on each file, matched by the find command.

I tried:

find / -name "*.err" -mtime -8 -exec send_notification {} \;

but it doesn't work. What should I do? I work in ksh on Hp-Ux.

Regards,
Pit
  #2 (permalink)  
Old 04-02-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
I think its not possible to execute function.Instead make a shell script send_not.sh and call that script in find command


Code:
send_not.sh
############
send_notification() {
...
}
send_notification $1
############


Code:
find / -name "*.err" -mtime -8 -exec /dir1/dir2/send_not.sh {} \;

  #3 (permalink)  
Old 04-02-2007
piooooter piooooter is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 24
Thank you for reply.

I know that I can place that function in a separate file. On that way it has been working for a long time but I was asked to place everything in one shell script.

Pit

Last edited by piooooter; 04-02-2007 at 02:03 PM..
  #4 (permalink)  
Old 04-02-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
for file in $( find / -name "*.err" -mtime -8 -print )
do
     send_notification $file
done

  #5 (permalink)  
Old 04-02-2007
piooooter piooooter is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 24
Thank you again for reply.

The last solution seems to be almost ok, but there is another problem. It executes the command

find / -name "*.err" -mtime -8 -print

and when finishes it goes inside for loop. Because the find command searches through very large storage system it is required that the send_notification function is executed for each found item at the time it's found.
  #6 (permalink)  
Old 04-02-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245

Code:
find / -name "*.err" -mtime -8 -exec send_notification {} \;

  #7 (permalink)  
Old 04-02-2007
piooooter piooooter is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 24
Quote:
Originally Posted by reborg
Code:
find / -name "*.err" -mtime -8 -exec send_notification {} \;
But, as I stated in the first post, the above command doesn't work!
Closed Thread

Bookmarks

Tags
mtime

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 04:48 AM.


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