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
DH_INSTALLDEB(1)						     Debhelper							  DH_INSTALLDEB(1)

NAME
dh_installdeb - install files into the DEBIAN directory SYNOPSIS
dh_installdeb [debhelperoptions] DESCRIPTION
dh_installdeb is a debhelper program that is responsible for installing files into the DEBIAN directories in package build directories with the correct permissions. FILES
package.postinst package.preinst package.postrm package.prerm These maintainer scripts are installed into the DEBIAN directory. Inside the scripts, the token #DEBHELPER# is replaced with shell script snippets generated by other debhelper commands. package.triggers package.shlibs These control files are installed into the DEBIAN directory. Note that package.shlibs is only installed in compat level 9 and earlier. In compat 10, please use dh_makeshlibs(1). package.conffiles This control file will be installed into the DEBIAN directory. In v3 compatibility mode and higher, all files in the etc/ directory in a package will automatically be flagged as conffiles by this program, so there is no need to list them manually here. package.maintscript Lines in this file correspond to dpkg-maintscript-helper(1) commands and parameters. However, the "maint-script-parameters" should not be included as debhelper will add those automatically. Example: # Correct rm_conffile /etc/obsolete.conf 0.2~ foo # INCORRECT rm_conffile /etc/obsolete.conf 0.2~ foo -- "$@" In compat 10 or later, any shell metacharacters will be escaped, so arbitrary shell code cannot be inserted here. For example, a line such as "mv_conffile /etc/oldconffile /etc/newconffile" will insert maintainer script snippets into all maintainer scripts sufficient to move that conffile. It was also the intention to escape shell metacharacters in previous compat levels. However, it did not work properly and as such it was possible to embed arbitrary shell code in earlier compat levels. The dh_installdeb tool will do some basic validation of some of the commands listed in this file to catch common mistakes. The validation is enabled as a warning since compat 10 and as a hard error in compat 12. SEE ALSO
debhelper(7) This program is a part of debhelper. AUTHOR
Joey Hess <joeyh@debian.org> 11.1.6ubuntu2 2018-05-10 DH_INSTALLDEB(1)
All times are GMT -4. The time now is 06:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy