summary: ksh scripting question

From: Polak, Jon <Jon_Polak_at_icgcomm.com>
Date: Thu Oct 23 2003 - 18:09:01 EDT
Thanks to all for the very prompt replies.  

(and also to everyone who was kind enough to inform me of their vacation
status)

Once again, thinking out-of-the-box solved the issue.  A very simple change
allows one script to do all the processing as in this version sent by Mr.
Schmidt.

###########

#!/bin/ksh

report_func () {
    LOGFILE=$1
    grep -i "my data"  $LOGFILE| awk '{ ----long awk script here----}'
}

for FIL in `find /usr/xyz -name "file00*" -mtime +30 {} \;`
do
report_func $FIL
done

###########

The only issue I see with this would be if the filenames had embedded
whitespace, which in my case they don't.  

Finally, As I was writing this summary, another method was suggested by Mr.
Caines, simplified as follows.  I will try this method too.

find ... | xargs my_function



Original post below:

to the ksh wizards...

I want to consolodate two ksh scripts into one but in this case I am not
sure if it is possible.  
Any suggestions would be greatly appreciated.

The first script is the main one that does a find command to invoke the
second script on each matching entry.

###########

#!/bin/ksh
# this is script1.ksh

find /usr/xyz -name "file00*" -mtime +30 -exec script2.ksh {} \;

###########
 
#!/bin/ksh
# this is script2.ksh

LOGFILE=$1
grep -i "my data"  $LOGFILE | awk '{ --------- long awk script here
---------}'

###########

Optimally I would like to define script2 as a function within the script1 as
in the following example.  

###########

#!/bin/ksh

report_func () {
    LOGFILE=$1
    grep -i "my data"  $LOGFILE| awk '{ --------- long awk script here
---------}'
}

find /usr/xyz -name "file00*" -mtime +30 -exec report_func {} \;

###########

Unfortunately the exec portion of the find command doesn't seem to have
visibility to the function, even if I export the function.  Has anyone ever
found a way to script something like this using just one ksh script?

Thanks 
Jon
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Thu Oct 23 18:08:57 2003

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:20 EST