|
Home > Archive > Unix Shell > January 2006 > Script endlessly looping
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Script endlessly looping
|
|
| jsciba@aegonusa.com 2006-01-05, 6:08 pm |
| The following script has a loop that executes ftp to look for a trigger
file on a remote server. If the file is found, the loop breaks and
another ftp is done to retrieve a zipped data file. It deletes the
trigger file and renames the data file on the remote server. Then the
script copies and unzips the data file. Finally, it removes the zipped
file and the trigger file from the local server. This works 99% of the
time flawlessly. But the last several days, the script performs all its
tasks and then starts executing the loop again. It has to be killed
manually. The script is executed by Informatica as a pre-session
script.
Can anyone spot a problem?
-------------------------------------------------------------------------------------------------------------------------
#!/bin/ksh
ftp_rc=0;export ftp_rc
rcnt=0;export rcnt
etlData='/vc/extract/MrkFncl';export etlData
etlArch='/vc/extract/MrkFncl/archive';export etlArch
etlLogs='/vc/extract/MrkFncl/logs';export etlLogs
shdir='/vc/extract/MrkFncl/scripts';export shdir
cd $etlData
#
****************************************
*********************************
# * Function to get files from ftp server
*
#
****************************************
*********************************
function GetData
{
ftp -v -n 999.999.99.9 <<EOF > $etlLogs/UKGetLog.log << not real
IP
user xxxxxxxx xxxxxxxx << not real
login
type binary
del mrsukext.bak
del mrsuktrg.rec
get mrsukext.rec
ren mrsukext.rec mrsukext.bak
quit
EOF
ftp_rc=$?
}
#
****************************************
*********************************
# * Check for trigger file on ftp server
*
#
****************************************
*********************************
function CheckTrigger
{
ftp -v -n 999.999.99.9 <<EOF > $etlLogs/UKGetLog.log << not real
IP
user xxxxxxxx xxxxxxxx << not real
login
type binary
get mrsuktrg.rec
quit
EOF
ftp_rc=$?
}
#
****************************************
*********************************
# * Function to check log file for successful login
*
#
****************************************
*********************************
function CheckLogFile
{
export FailCode=`grep -c "logged in" $etlLogs/UKGetLog.log`
if [[ $FailCode = 0 ]]
then
exit 3
fi
}
#
****************************************
*********************************
# * Function to check for the trigger file
*
# * If file doesn't exists, process sleeps for 600 seconds and trys
again*
#
****************************************
*********************************
until false
do
CheckTrigger
if [ -f $etlData/mrsuktrg.rec ]
then
break
fi
sleep 600
done
#
****************************************
*********************************
# * Function to get the data file
*
#
****************************************
*********************************
GetData
CheckLogFile
#
****************************************
*********************************
# * Function to copy the data file to backup
*
# * Function to unzip the data file
*
#
****************************************
*********************************
cp mrsukext.rec $etlArch/mrsukext.rec_`date '+%m%d%y%H%M'`
unzip -p mrsukext.rec > $etlData/mrsukext.dat
rm mrsukext.rec
rm mrsuktrg.rec
exit $retcode
| |
| Chris F.A. Johnson 2006-01-05, 6:08 pm |
| On 2006-01-05, jsciba@aegonusa.com wrote:
> The following script has a loop that executes ftp to look for a trigger
> file on a remote server. If the file is found, the loop breaks and
> another ftp is done to retrieve a zipped data file. It deletes the
> trigger file and renames the data file on the remote server. Then the
> script copies and unzips the data file. Finally, it removes the zipped
> file and the trigger file from the local server. This works 99% of the
> time flawlessly. But the last several days, the script performs all its
> tasks and then starts executing the loop again. It has to be killed
> manually. The script is executed by Informatica as a pre-session
> script.
>
> Can anyone spot a problem?
>
> -------------------------------------------------------------------------------------------------------------------------
>
> #!/bin/ksh
>
> ftp_rc=0;export ftp_rc
> rcnt=0;export rcnt
>
> etlData='/vc/extract/MrkFncl';export etlData
> etlArch='/vc/extract/MrkFncl/archive';export etlArch
> etlLogs='/vc/extract/MrkFncl/logs';export etlLogs
> shdir='/vc/extract/MrkFncl/scripts';export shdir
> cd $etlData
You should check that cd succeeds.
[snip]
> # ****************************************
*********************************
> # * Check for trigger file on ftp server *
> # ****************************************
*********************************
>
> function CheckTrigger
> {
> ftp -v -n 999.999.99.9 <<EOF > $etlLogs/UKGetLog.log << not real IP
> user xxxxxxxx xxxxxxxx << not real login
> type binary
> get mrsuktrg.rec
> quit
> EOF
> ftp_rc=$?
> }
[snip]
> # ****************************************
*********************************
> # * Function to check for the trigger file *
Function? I don't see a function, just a loop.
> # * If file doesn't exists, process sleeps for 600 seconds and trys again*
> # ****************************************
*********************************
>
> until false
That is the same as the more common:
while true
> do
> CheckTrigger
>
> if [ -f $etlData/mrsuktrg.rec ]
Since you have cd-ed to $etlData, why bother putting it there?
if [ -f mrsuktrg.rec ]
> then
> break
> fi
>
> sleep 600
> done
If this loop never breaks, then the file is never retrieved, or
it's not in the place you are looking for it.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
|
|
|
|
|