Sponsored Content
Full Discussion: Endless Loop
Top Forums Shell Programming and Scripting Endless Loop Post 302203019 by JeffR on Friday 6th of June 2008 11:09:10 AM
Old 06-06-2008
Endless Loop

Hi,
I'm pretty new to UNIX shell scripting and need some help. We have an Informatica interface that dumps any files that have errors into a directory. I need to check that directory periodically for any of up to 9 files that might be in it and run a specific process for each file found. The directory could (and hopefully would be) empty.

I've gotten some help from some of the folks here and have worked out some of the initial problems, but it goes into an endless loop and I have to stop it. I'm missing something.

Any help would be greatly appreciated.

Here is the test code without the actual processes:
Code:
#!/bin/ksh

ls /home/inform/LeanLogistic/bkp | while read filename
echo $filename
do
echo 'did do statement'

	if [ "$filename" = "CX_ORDER_LOAD_SHIPMENTexport.csv" ]
       then
       /usr/bin/echo "CX_ORDER_LOAD_SHIPMENT file." 
	elif [ "$filename" = "CX_CHARGEexport.csv" ]
	then 
	  /usr/bin/echo "CX_CHARGE file." 
	elif [ "$filename" = "CX_LOAD_HISTORYexport.csv" ]
	then
	  /usr/bin/echo "CX_LOAD_HISTORY file." 
	elif [ "$filename" = "CX_DEDICATED_EQUIPMENTexport.csv" ]
	then
	  /usr/bin/echo "CX_DEDICATED_EQUIPMENT file." 
	elif [ "$filename" = "CX_LOAD_NOTEexport.csv" ]
	then
	  /usr/bin/echo "CX_LOAD_NOTE file."
	elif [ "$filename" = "CX_PRODUCT_INFOexport.csv" ]
	then
	  /usr/bin/echo "CX_PRODUCT_INFO file." 
	elif [ "$filename" = "CX_RATE_CHANGE_REQUESTexport.csv" ]
	then
	  /usr/bin/echo "CX_RATE_CHANGE_REQUEST file."
	elif [ "$filename" = "CX_SERVICE_REQUESTexport.csv" ]
	then
	  /usr/bin/echo "CX_SERVICE_REQUEST file." 
	elif [ "$filename" = "CX_SERVICE_FAILUREexport.csv" ]
	then
	  /usr/bin/echo "CX_SERVICE_FAILURE file." 
	fi
echo 'did if statement'
done

Below is the output it produces when all 9 files are in the directory. It loops through and reads all the files, but then just keeps looping.

CX_CHARGEexport.csv
did do statement
CX_CHARGE file.
did if statement
CX_DEDICATED_EQUIPMENTexport.csv
did do statement
CX_DEDICATED_EQUIPMENT file.
did if statement
CX_LOAD_HISTORYexport.csv
did do statement
CX_LOAD_HISTORY file.
did if statement
CX_LOAD_NOTEexport.csv
did do statement
CX_LOAD_NOTE file.
did if statement
CX_ORDER_LOAD_SHIPMENTexport.csv
did do statement
CX_ORDER_LOAD_SHIPMENT file.
did if statement
CX_PRODUCT_INFOexport.csv
did do statement
CX_PRODUCT_INFO file.
did if statement
CX_RATE_CHANGE_REQUESTexport.csv
did do statement
CX_RATE_CHANGE_REQUEST file.
did if statement
CX_SERVICE_FAILUREexport.csv
did do statement
CX_SERVICE_FAILURE file.
did if statement
CX_SERVICE_REQUESTexport.csv
did do statement
CX_SERVICE_REQUEST file.
did if statement

did do statement
did if statement

did do statement
did if statement

did do statement
did if statement

did do statement
did if statement

did do statement
did if statement
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Endless loop - Fork function failed?

I need a quick script that will serve as a sort of "real time monitor" for watching some log files. I am using Bourne shell in HP-UX 10.20. I have basically created a script that never ends, unless of course I manually terminate it. Here's the script (it's called qhistory): clear echo "REAL... (3 Replies)
Discussion started by: cdunavent
3 Replies

2. HP-UX

printer spewing out endless copies

Hi I've set up a remote IP-addressed printer using lpadmin on a hp-ux server. It is - as far as I can tell - identical to another printer on the system of the same model type. The default printer works fine with the lp command; the new printer sends endless copies and the job has to be cancelled... (2 Replies)
Discussion started by: ewans
2 Replies

3. Shell Programming and Scripting

calculating endless columns

I have about 5000 columns of data that i need to convert all of it into pecentages. for shorter colums i have been using this code: {print $1/($1+$2)*100,$2/($1+$2),$3/($3+$4)*100 .....} but this is a teadious process... is there anyway to do it without having to write all of them out? sample... (20 Replies)
Discussion started by: chronicx
20 Replies

4. Shell Programming and Scripting

[PHP] endless loop mimics a cron. Make sure only one instance is running

Hi, PHP user here. I'm using an endless loop to perform to mimic a cron. The script does something every 20 minutes. It sleep()s in the meantime. I have various checks that ensure that only instance can run, including a "gentleman agreement" locked file. However, I'd like to make sure... (2 Replies)
Discussion started by: jjshell
2 Replies

5. Shell Programming and Scripting

Preventing an endless loop with recursive grep

When finding a string in files within a directory, one can use this: grep -r "searchstring" dir/subdir/ > listofoccurrences.txt For brevity sake one can enter the intended directory and use this: grep -r "searchstring" . > listofoccurrences.txt which as I found out leads to an endless loop,... (2 Replies)
Discussion started by: figaro
2 Replies

6. Shell Programming and Scripting

KSH - Issue with endless loop.

First time post. I did a search so I didn’t see this specific issue. It seems to be a head scratcher for me. I have an hourly job that on rare occasions, gets into an endless loop. I’ve tried different scenarios but the current version does basically the following. Find all the *.arc files and... (18 Replies)
Discussion started by: Sylvan303
18 Replies

7. Shell Programming and Scripting

[Solved] Endless while loop when compare files

Hi All, I've written a script to read 2 files and compare the contents using while loop but somehow when $line is not found in test2, the script will continue looping. Below is my code, pls advise what could went wrong TIA Nick for line in test1.txt | while read line do grep -i... (4 Replies)
Discussion started by: Nick1971
4 Replies

8. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

9. Shell Programming and Scripting

Script runs in endless loop

Hi, AM very new to shell scripting and try to run a simple do while loop statement, but it ends up running endlessly. please can anyone assist, dunno what am doing wrong, any useful suggestions will be welcomed. #!/bin/ksh ### To check a running process instance #################... (5 Replies)
Discussion started by: bayoo
5 Replies

10. UNIX for Beginners Questions & Answers

Help with accidental endless loop

I was practicing writing simple loops as I am a new bash user and I created this script, which turned out to be an endless loop where the echo output does not stop and I do not see where my mistake is. #!/bin/bash echo 'enter a number from 1 to 100' read number while do ... (2 Replies)
Discussion started by: goldenlinx
2 Replies
POE::Loop::Tk(3pm)					User Contributed Perl Documentation					POE::Loop::Tk(3pm)

sub skip_tests {
  return "Tk needs a DISPLAY (set one today, okay?)" unless (
    (defined $ENV{DISPLAY} and length $ENV{DISPLAY}) or $^O eq "MSWin32"
  );
  my $test_name = shift;
  if ($test_name eq "k_signals_rerun" and $^O eq "MSWin32") {
    return "This test crashes Perl when run with Tk on $^O";
  }
  return "Tk tests require the Tk module" if do { eval "use Tk"; $@ };
  my $m = eval { Tk::MainWindow->new() };
  if ($@) {
    my $why = $@;
    $why =~ s/ at .*//;
    return "Tk couldn't be initialized: $why";
  }
  return; }

NAME
POE::Loop::Tk - a bridge that allows POE to be driven by Tk SYNOPSIS
See POE::Loop. DESCRIPTION
POE::Loop::Tk implements the interface documented in POE::Loop. Therefore it has no documentation of its own. Please see POE::Loop for more details. POE::Loop::Tk is one of two versions of the Tk event loop bridge. The other, POE::Loop::TkActiveState accommodates behavior differences in ActiveState's build of Tk. Both versions share common code in POE::Loop::TkCommon. POE::Loop::Tk dynamically selects the appropriate bridge code based on the runtime environment. SEE ALSO
POE, POE::Loop, Tk, POE::Loop::TkCommon, POE::Loop::PerlSignals. AUTHORS &; LICENSING Please see POE for more information about authors, contributors, and POE's licensing. perl v5.10.1 2010-04-11 POE::Loop::Tk(3pm)
All times are GMT -4. The time now is 12:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy