Shell script not processing if statement properly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script not processing if statement properly
# 1  
Old 05-08-2007
Shell script not processing if statement properly

Hi I am trying to create a shell script that will

look for a contracthead file first and if the contract head file does not exist on day1 exit script.

Now on day2 if contracthead exists or not run the script uploading files in order
such as contract line then contract contact

so the whole order on day1 is
contracthead
contractline
contractcontact

on day2
if it exists or not run the script like the order above even if files are missing.
Now this is the script i came up with.

basically the if statement for the days block seems not be working
it works determinig day 1 and 2 but it does nto run the script as i want it to.

So far.g if it has a contracthead ont he first day and no days file.
It will upload contract head and go to the else statement and create the days file. It should not do this because the contracthead file exists. If it did not exist then the days file will be created.

Could you tell me where i am going wrong please.

Code:

Code:
#!/bin/bash
# DATE varaible is used to archive the files after ftp
DATE=`/bin/date +%Y%m%d%H%M`
# TODIR variable is the target directory for the file on remote system 32x
TOARCHIVEDIR=/home/tibco/tibco/archive
# 32x
TODIR=/home/tibco/tibco/AIS_FTP/test/inbound/Staging
# FROMDIR variable is the source directory of the file on the local system   5x
FROMDIR=/home/tibco/ems/FTP/test/inbound/Staging/FTPComplete
# ARCHDIR variable is the directory file get moved to after tranfer 5x
ARCHDIR=/home/tibco/archive/testFtp2_32X  

pwd=`pwd`
echo $pwd
cd $FROMDIR
STEXT="The following files were received in: /home/tibco/ems/FTP/test/inbound/Staging/FTPComplete \n"
ETEXT="The following files were NOT FOUND in: /home/tibco/ems/FTP/test/inbound/Staging/FTPComplete \n"


########Running Loop########
for file in int_sap_contracthead*.txt 
int_sap_contractline*.txt
int_sap_contractcontact_*.txt

do
	echo $file
	if [ -f $file ]
	then
		#echo " file $file exists"
		STEXT="%10s $STEXT \n $file "
		#echo " $STEXT "
	else
		ETEXT="%10s $ETEXT \n $file "
		#echo " $STEXT "
	fi
done
SUCCESS=`printf "$STEXT " `
FAIL=`printf "$ETEXT " `



##################### Checkign if the days file exists######################

NF=Contracthead file not found
NFEMAIL=Contracthead file not found

if [ -e "days" ]
   then
       echo "*** The days file exists ***"
       rm days
       echo "*** removing the days file ***"


       echo " ------ This is day 2 - all files are loading ------ "\n\n\n
    ################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contracthead_*.txt

bye
EOF
############  END FTP ###############       
     echo "*** -- UPLOADING FILE CONTRACTHEAD -- ***"
sleep 8
           elif [ -e "int_sap_contracthead_*.txt" ]
              then
             echo "*** -- UPLOADING FTP -- ***"
################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contracthead_*.txt

bye
EOF
############  END FTP ###############
                  echo "int_sap_contracthead_*.txt File is uploading"   
           
                  else
                      echo "1" > days
                      echo "Files will not upload today"  
                      exit           
fi

sleep 8
##################### End##################

echo "code still running"

if [ "$file" = "int_sap_contractline*.txt" ]
   then
      ################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contractline_*.txt

bye
EOF
############  END FTP ###############
      echo "contracthead File is uploading"  
sleep 8
else 
echo "there is NO contractcontact File to upload"  
fi


if [ "$file" = "int_sap_contractcontact*.txt" ]
   then
       ################ FTP ################
ftp -i -n server <<EOF
user test 45678
cd $TODIR
pwd
lcd $FROMDIR
bin
mput int_sap_contractcontact_*.txt

bye
EOF
############  END FTP ############### 
      echo "contractcontact File is uploading"   

else echo "there is NO contractcontact File to upload"
fi



HEADER="FTP Summary of the files "
	
mail -s "$HEADER" test@domain.com <<EOF
$SUCCESS
	$FAIL
EOF

# create the archive directory based on timestamp and move files
cd $ARCHDIR
mkdir $DATE
mv $FROMDIR/int_sap_contractline_*.txt $ARCHDIR/$DATE/
mv $FROMDIR/int_sap_contractcontact $ARCHDIR/$DATE/
mv $FROMDIR/int_sap_contracthead_*.txt $ARCHDIR/$DATE/
exit

# 2  
Old 05-08-2007
elif [ -e "int_sap_contracthead_*.txt" ]

You are testing for the existence of a file with an asterisk truly in the filename. Removing the quotes will make it work provided there is exactly one matching file name.

elif ls int_sap_contracthead_*.txt >/dev/null 2>&1
will work with many names.


if [ "$file" = "int_sap_contractline*.txt" ]
also not gonna fly. Double brackets would work if you unquote the pattern. Or use a case statement.
# 3  
Old 05-08-2007
Hi Perderabo

Thank you very much that did work by removing the quotes. I am a newbie doing this. So I appreciate all the help you gave me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

2. Shell Programming and Scripting

If then Else statement in shell script

Hi, I am having a shell Script which i need to modify. I am new to shell scripting , needs help. The Logic which needs to be incorporated is as follows :- The script need to check the length of first Line in a data fine and of the length of the file is > 130 then validated the input... (2 Replies)
Discussion started by: mvichare
2 Replies

3. Shell Programming and Scripting

Shell script not working properly

Hello, i have below shell script to process ftp get from server and create file list afte finish. this shell scipt has 6 parameter input. unfortunately, it is only working to get the file and terminated before creating file list. please help. thanks, #!/bin/ksh ## example usage :... (3 Replies)
Discussion started by: daryatmo
3 Replies

4. Shell Programming and Scripting

File Processing in shell script

i have a file with following type of data abcd : gggggg gggggg ; 1234 gggggg ; 5678 gggggg ; 3434 gggggg ; 6565 gggggg ; 1231 1234 ; vvvv ;Eng=Myfirstname 5678 ; xyzf ;Eng=Mysecondname 3434 ; xyzf ;Eng=Mythirdname 6565 ; xyzf ;Eng=Mysfourthname 1231 ; xyzf ;Eng=Mysfifthname... (7 Replies)
Discussion started by: telangmadhuri
7 Replies

5. Shell Programming and Scripting

Help with shell script for url processing

Hi, My objective is to make a shell script that, when run, you can input multiple links at once. text is then inserted between the http:// part and the following url. example : http://google.be ==> http://sometext.google.be it would be great if it could then open all the created links (wich... (5 Replies)
Discussion started by: tooster
5 Replies

6. Shell Programming and Scripting

2 file processing script in C shell

I want to use an awk for the following scenario but not sure if it will work or not. I have two input file: F1 and F2 F1 02 05 08 F2 00 01 02 03 04 05 06 07 08 09 10 (1 Reply)
Discussion started by: jclanc8
1 Replies

7. Shell Programming and Scripting

Shell Script Email not working Properly

Hi GURU's, I'm using a Shell Script to send email's as an attachment. I'm Storing the email address in a table and catching in a variable. MAILLIST=`noarg sqlplus -s $OraUsr << EOF set heading off set feedback off set echo off SELECT email_ids FROM tpemail_table WHERE... (9 Replies)
Discussion started by: karthikraj
9 Replies

8. UNIX for Dummies Questions & Answers

Issue with shell script: not detecting file properly

The following script is meant to check the presence of a file - called filename0.94.tar.gz - and uncompress it: #!/bin/sh # check presence of file VERSION=0.94 if ; then # file not present: abort echo "Files cannot be found." #exit 1 (commented out this line, so we can see how the... (2 Replies)
Discussion started by: figaro
2 Replies

9. Shell Programming and Scripting

I can't seem to pass variables properly into a nawk statement

Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to. The goal: -to... (6 Replies)
Discussion started by: DeCoTwc
6 Replies

10. Shell Programming and Scripting

Shell Script syntax for XML processing

Hi All, I am new to Shell scripting. I have a log file containing XML Messages.Each XML Message is accompanied with a timestamp.I need to count the the number of messages that get logged in a particular timeinterval.Is there any command/Syntax to achieve this. Any code/example is... (5 Replies)
Discussion started by: vignesh53
5 Replies
Login or Register to Ask a Question