Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger UNIX job to execute on demand 2

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
Our database sits on the UNIX box. We have a web-based application that allows our users to run an Oracle stored procedure that extract files into the UNIX server. I would want to execute a UNIX job that will automatically FTP these files into our mainframe system and the only way I can
do this is to cron the FTP process as:
* * * * * /home/ftpthis, and this doesn't seem productive.
Is there any other way (in UNIX or maybe Oracle?)to trigger this job based on the availabily of the files.
 
Hi,
you could have a script which never exits. that way you wouldn't be constrained by the 1 minute execution of CRON.


while ( 1 )
set a = `ls -1 theftpdir | wc -l`
if ( $a > 0 )
transfer the files
delete the files
endif
sleep 30 ;
end


 
Be careful, if the Oracle stored procedure takes a long time to create/fill the result file, you could to detect and transfert this file before the file is complete.

A solution (not bullet proof) is verify that the size of the file is stable :
[tt]
# CheckFile - Check file for availabily
# Arg(s) $1 = File
# Env. CHECK_SIZE_DELAY = Interval between two file size verification
# CHECK_SIZE_RETRIES = Max file size verification retries
# Status 0 = File Ok
# 1 = File unavailable
#

File=$1
: ${CHECK_SIZE_DELAY:=15}
: ${CHECK_SIZE_RETRIES:=4}

FileSize=-1
Retries=0
while :
do
[ -r "$File" ] || exit 1
fs=`ls -l "$File" | awk '{print $6}'`
[ "$fs" -eq "$FileSize" ] && exit 0
FileSize=$fs
Retries=`expr $Retries + 1`
[ $Retries -ge $CHECK_SIZE_RETRIES ] && exit 1
sleep $CHECK_SIZE_DELAY
done
exit 1
[tt]

The tdatgod script becomes :
[tt]
while ( 1 )
do
for file in `ls -1 theftpdir`
do
if CheckFile $file
then
# transfer the file
# delete the file
endif
sleep 30 ;
done
done
[tt]


Jean Pierre.
 
Thanks guys!!! As I am new with UNIX programming, I will have to digest your recommendations and consult my reference books. Although this job will only run one whole day, will there be some "overhead" involved if I run this job the whole day that day.
 
Hi,
Yes you need some way to verify the file is completely there from the SP and the provided function will help that.

on the related not what is the REQUIREMENT for INSTANT transfer?

I mean could you kick off the script once an hour and satisfy your users?

If you are worried about the script running and consuing resources all day you could updatwe it to run for 1 hour, start a new copy of itself and then exit.

I am not too sure if this proper SH code so If I get it backwards let me know.

inplace of the while ( 1 ) put

x=0
while ( $x < 120 )

and for the DONE of the while add

x = `expr $x + 1`
done

$0 &

exit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top