Stumped


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stumped
# 1  
Old 05-30-2008
Question Stumped

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 for any of up to 9 files that might be in it and run a specific process for each file found.

Here's what I have, but it hangs at the cat line. Seems like it should be pretty simple, but there's just something that I'm not understanding. The IF statement I'm using works because I have it in another script that works, it's just long so I abbreviated.

#!/bin/ksh

ls -l /home/inform/LeanLogistic >$LIST_OF_FILES

cat $LIST_OF_FILES|while read LINE

do

filename=`echo $LINE|awk '{print $9}'`

if [ "$filename" = "CX_ORDER_LOAD_SHIPMENTexport.csv" ];
then ...
elif [ "$filename" = "CX_CHARGEexport.csv" ];
then ...
elif [ "$filename" = "CX_LOAD_HISTORYexport.csv" ];
then ...
# goes on to check for the other 6 files, you get the picture
fi ...
done
# 2  
Old 05-30-2008
Question some things to think about...

a) can you edit and/or remember when posting code to use the codetag's? Highlight the code and then select the # icon - this will keep the line formatting.
b) do you know if anything exists in $LIST..
c) add some well-placed echo commands to show variables at steps as this will confirm data and also allow tracking of program progress
d) not sure of the purpose of the ; at end of the if ... line as your then appears to be on the next programming line
e) I often use the format
Code:
while read mydata
   do
   blah blah blah
done < inputrecords

as I find it easier to read; although your choice might be ok
# 3  
Old 05-30-2008
You don't have to use temporary file, try something like:

Code:
ls | while read filename
do
  if [ "$filename" = "CX_ORDER_LOAD_SHIPMENTexport.csv" ]
  then ...

  fi ...
done

Regards

Last edited by Franklin52; 05-30-2008 at 06:37 PM.. Reason: remove ";" after is statement
# 4  
Old 05-30-2008
Thanks for the help. Sorry about the code tags Joey, I didn't know they existed, but I'll use them from now on.
Franklin, I used your method in a test script against a test directory that has all the files in it and it lists the files, but then goes into an endless loop. Obviously I'm still missing something. Any help will be appreciated.

Here's the code:
Code:
#!/bin/ksh

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

	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'
done


Here's the output it produces. I have to stop it or it will continue to loop.

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

did do
did if

did do
did if

did do
did if

did do
did if

did do
did if
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Stumped .. is this a command line arg?

I need a bit of explanation: LogFile=${LOGS_DIR}/${1}_$$ I know: - LOGS_DIR is an environment variable - $$ is the PID ... but what is ${1} ?? Is it another method to access a command line variable, or the job name? Thanks! Jon (3 Replies)
Discussion started by: jdorn001
3 Replies

2. Shell Programming and Scripting

Stumped on simple BASH Script

Hello All, First and foremost, if I have posted this question in the wrong forum/section, I apologize. Okay so here is my dilemma. I have written a BASH script that automatically restarts a tomcat on a given server. That part was simple enough. However, now I would like to not only restart... (14 Replies)
Discussion started by: UNM_Lobo
14 Replies

3. Shell Programming and Scripting

Command not found in shell script - stumped for 4 days

Hello, I like to begin with :wall:.. literally... It has been 4 days and I have no idea how to fix it. Environment - AIX 5.3 I wrote a script to call on ssh to log into another box via PKA to do something else. If I run the script on the terminal, it works 100%. If the SAP customised... (11 Replies)
Discussion started by: plonkagain
11 Replies

4. Shell Programming and Scripting

perl replace command, stumped!

Ok, I stole some code from a program that takess a hash of a password from PasswdMD5 and replaces it in the /etc/shadown file on a linux system. I run his program and it's fine. Well I took the same code and put it in another program that won't ask for prompgx and such and this code won't work:... (2 Replies)
Discussion started by: benefactr
2 Replies

5. Shell Programming and Scripting

I Am Stumped, Please Help

I have a CSV file that I am trying to parse with awk in a table. I think I am going about this the wrong way. I can't get the awk arrays to output with a tab between them in one line. They print out vertically and I need them to print out horizontally. WHAT AM I DOING WRONG?? I want to know if... (21 Replies)
Discussion started by: timj123
21 Replies

6. UNIX for Dummies Questions & Answers

RegEx question has me stumped

Hi All, I'm fairly new to Regular Expressions, and have made some decent progress, but this one has me scratching my head. I'm trying to match the class name in my scripts as shown in the examples below. Any ideas? Thanks! -Mark :: Looking for a regex to match the red text :: import... (7 Replies)
Discussion started by: tolmark
7 Replies

7. IP Networking

httpd.conf - stumped

Have been asked to remove all images from being logged to the access_log ... where am I going wrong?<VirtualHost 123.456.789.99> ServerName www.somedomain.com.au DocumentRoot /agents/tts Redirect /wap http://somewap.com.au/traveler LogFormat "%v %h %l %u %t \"%r\" %>s %b" comonvhost... (2 Replies)
Discussion started by: Cameron
2 Replies
Login or Register to Ask a Question