How can I execute own ksh function in find -exec


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I execute own ksh function in find -exec
# 1  
Old 04-02-2007
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  
Old 04-02-2007
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  
Old 04-02-2007
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 timeSmilie but I was asked to place everything in one shell script.

Pit

Last edited by piooooter; 04-02-2007 at 02:03 PM..
# 4  
Old 04-02-2007
Code:
for file in $( find / -name "*.err" -mtime -8 -print )
do
     send_notification $file
done

# 5  
Old 04-02-2007
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  
Old 04-02-2007
Code:
find / -name "*.err" -mtime -8 -exec send_notification {} \;

# 7  
Old 04-02-2007
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find: missing argument to `-exec' while redirecting using find in perl

Hi Friends, Please help me to sort out this problem, I am running this in centos o/s and whenever I run this script I am getting "find: missing argument to `-exec' " but when I run the same code in the command line I didn't find any problem. I am using perl script to run this ... (2 Replies)
Discussion started by: ramkumarselvam
2 Replies

2. Shell Programming and Scripting

exit status from ksh script exec from java using runtime

how do i get the exit status from a ksh or perl script executed in a java program using Runtime? (1 Reply)
Discussion started by: twk
1 Replies

3. Shell Programming and Scripting

-exec cmd in ksh script

Hi, I discovered the following single-line script works very well to cp a large number of files from a source directory to a destination directory while avoiding the "argument list too large" error: # cpmany - copy large number of files # Takes two parameters - source dir, destination dir... (14 Replies)
Discussion started by: Tanuka
14 Replies

4. Shell Programming and Scripting

understand the function to execute

Gurus, Can you please tell me why this script is executing but i am getting no result...also can you tell me what is this gettime() doing? in a script i wrote this hour.SH -------------------------- gettime() { date '+%H' | { read hour TIME=${hour} } } : ----------------------... (2 Replies)
Discussion started by: RubinPat
2 Replies

5. Shell Programming and Scripting

How to execute piped command using exec or system

Hi All, I want to execute a piped command like 'ls /opt | grep xml' using array as parameters list. How can I do that? (2 Replies)
Discussion started by: bharadiaam
2 Replies

6. UNIX for Dummies Questions & Answers

Execute "find . -exec grep" in desending Order

Hi Xperts, I've one query for you. Please help me solving this. Below command is taking long time to fetch names of the files which contain string "475193976" because folder contains millions of files. I agree that this is what this function suppose to do. Correct.. But can it be possible... (6 Replies)
Discussion started by: gav_dhiman
6 Replies

7. Programming

Runtime.getSystem.exec() function waits for child

Runtime.getSystem.exec() waits for child process to complete .. I do not want to wait for the child process to complete ..what is the option which has to be used ? (2 Replies)
Discussion started by: shafi2all
2 Replies

8. UNIX for Advanced & Expert Users

exec to call specific function in C prog

I would like to call a particular function in a C program using execl(). Is this possible using execl or anyother function ? Thanks (2 Replies)
Discussion started by: vpraveen84
2 Replies

9. Programming

alternatives of exec() system function

Hi , Can anybody name any System Function in C/C++ for Sun-Solaris (unix) platform which can serve the alternative of execl() system function. Actually I am calling a fork-execl() pair and then making an interprocess communication between these two(parent-child process). But the problem is... (3 Replies)
Discussion started by: Raj Kumar Arora
3 Replies

10. Programming

How to periodically execute a function in C ??

Hi, I am looking for a C library feature, to which I can say execute a function every 10 seconds. for Eg #include <timer_lib.h> fun1(){ printf("I am still cool "); } int main(){ run(10,&fun1); // Should register & execute the function fun1 every 10 seconds return 0x0; }... (24 Replies)
Discussion started by: RipClaw
24 Replies
Login or Register to Ask a Question