Script not executing second loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not executing second loop
# 1  
Old 05-07-2008
Script not executing second loop

I have a server that receives backup files from several servers. Each server has its own directory to scp their files into, some of the files are received as .tar files and need to be compressed before being dumped. When the scp of the tar file is complete a file named 'flag' is also sent to indicate that the scp of the zip file is complete.

The following script is supposed check for any existing flag files and .tar files and run bzip2 on any .tar files found.
The specific problem is that, on the first while loop if no flag or tar file is found the second loop is not initiated. If the data for the first loop exists then both loops run as expected. (Currently only data for two servers are included for testing).

I've looked and looked for the error in my logic and it eludes me. Could someone point out my blind spot?

The data file being read is appended after the code.

Thanks
Thumper

Code:
#!/bin/bash
#
# set -n  
 set -x  

##########################################################
####################### FUNCTIONS ######################
##########################################################
file_exists () {
    echo "ENTERING FILE_EXISTS"
    echo "the value of \$1 is ${1}"
    echo "the value of \$2 is ${2}"

    if [ -e ${1} ]  #test for the flag file
        then
            if [ -e ${2} ]  #test for the .tar file
                then
                     `bzip2 ${2}`   #bzip the .tar file
                     `rm ${1}`       #remove the flag file
                else  #no .tar file found
                    mail -s "No ${2} file found" thumper@somewhere.net
            fi
        else  #no flag file found
                        mail -s "No ${1} file found" thumper@somewhere.net
    fi
    return 0
}
#### end
##########################################################
#################### MAIN ################################
##########################################################

while IFS=: read dir sname flag ext
do
        VAL_1="/$dir/$sname/$flag"
        VAL_2="/$dir/$sname/$ext"
        echo ${VAL_1}; echo ${VAL_2}
#       echo "Calling file_exists"

            file_exists ${VAL_1} ${VAL_2}

#       echo "Exited file_exists"
        echo "VAL_1 is ${VAL_1}"
        echo "VAL_2 is ${VAL_2}"
        echo "\$? is $?"
done < /root/scripts/bz-data
# End of script


DATA FOR READ STATEMENT
/root/scripts/bz-data
archive:yoda:flag:*.tar
archive:chewy:flag:*.tar
# 2  
Old 05-07-2008
I've tested your script but on my Linux box I have no problems at all... I've tried all the possible missings of flag/tar files combinations but I can't reproduce your behavior.

Code:
test ~ $ bash --version
GNU bash, version 3.2.33(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

Maybe your issue is related to a specific OS and/or bash versions Smilie
# 3  
Old 05-07-2008
Quote:
Originally Posted by robotronic
I've tested your script but on my Linux box I have no problems at all... I've tried all the possible missings of flag/tar files combinations but I can't reproduce your behavior.

Code:
test ~ $ bash --version
GNU bash, version 3.2.33(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

Maybe your issue is related to a specific OS and/or bash versions Smilie
I didn't realize that the OS or bash version could cause such an issue.
Anyhow the OS is
# uname -a
Linux sport 2.6.11.4-21.17-default #1 Fri Apr 6 08:42:34 UTC 2007 i686 athlon i386 GNU/Linux

And the bash version is
# bash --version
GNU bash, version 3.00.16(1)-release (i586-suse-linux)
Copyright (C) 2004 Free Software Foundation, Inc.
and the bash version is

If anyone knows of a cause for this problem I would appreciate help.

Thanks again
Thumper
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing passing and executing select statement in loop

Hi, i want to do the following: Grep the following kind of strings for the 15digit ID which is stored in filename1: "14:06:51.396 INFO BMCREMEDYSD INPUT-ACTION Failed to retrieve Remedy Incident Modification record: 000000000039047 org.apache.axis2.AxisFault: Read timed out - complete... (9 Replies)
Discussion started by: Khushbu
9 Replies

2. Shell Programming and Scripting

"if" Loop not working when executing script using cron

I am facing this weird issue where the script is working fine from the command line but when I am executing it from cron though it is working fine but the "if" loop is processing else part though I know that the if part of the logic is true and ideally the loop should execute the if portion. ... (3 Replies)
Discussion started by: sk2code
3 Replies

3. Shell Programming and Scripting

Help with executing awk and While loop

Hi All, I have a file say, sample.txt Source Name: xxx Department|Revenue 1001|3252 1002|3345 I am using the above file in one of my script. I need to read from Line 3 of the above the file and do some process. My script has a code: awk 'NR > 2' sample.txt | while read Dep; do... (9 Replies)
Discussion started by: machomaddy
9 Replies

4. Shell Programming and Scripting

Problem in executing For loop....

Hi frnds I trying to execute the following ksh, #!/bin/ksh file=$OBS_APP_PATH/config/com/uhg/obs/inbound/configs/ServiceFeeDetail.xml inputFileDir=$OBS_APP_PATH/config/com/uhg/obs/inbound/configs/ echo $file echo $cntWrd if then echo "Inside IF" for i in 'ls -t1... (7 Replies)
Discussion started by: balesh
7 Replies

5. Shell Programming and Scripting

cd command not executing in if else loop

Hi, I am executing below script s1=`pwd` s2=/space if then echo "done" else echo "mistake" cd /tmp fi I am not able to migrate to /tmp directory if the condition is not true.However mistake is being printed.Means cd command is not working here.All other commands except cd are... (3 Replies)
Discussion started by: d8011
3 Replies

6. Shell Programming and Scripting

error executing script in a while loop

Im unable to run scripts when i read each script thru a while loop. Is this way of execution thru while loop is wrong or is there any error in the script. I get the following error msg and i use ksh. ./vftest.ksh: ./add.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT: not found ... (7 Replies)
Discussion started by: michaelrozar17
7 Replies

7. Shell Programming and Scripting

Variables of executed script available in executing script

Hi, I have a script get_DB_var.ksh which do a data base call and get some variables as below: sqlplus -silent $user/$pass@dbname <<END select col1, col2, col3 from table_name where col4=$1; exit; END Now I want to access all these variables i.e.... (9 Replies)
Discussion started by: dips_ag
9 Replies

8. UNIX for Advanced & Expert Users

Executing a shell script from windows;script present in unix

I need to execute a shell script kept in unix machine from windows. User id, password area available. For eg. There's a shell script wich moves all the logs kept in my home directory to a directory named LOGS. Now i need to get this done through windows; either using a batch file, or java... (4 Replies)
Discussion started by: rajneesh_kapoor
4 Replies

9. Shell Programming and Scripting

ssh and executing a for loop

Hi all, I am trying to run a script which is expected to do: on the remote machine, There are two directories /export/home/abc1,/export/home/abc2 i am trying to do, ssh SERVERNAME "for i in `ls -l /export/home/abc*|awk '{print $9}'`; do cd $i; ls -l; done" But its not working ,iam... (11 Replies)
Discussion started by: Jartan
11 Replies

10. Shell Programming and Scripting

Print out loop index on the console after executing each sybase DB query

Hello Guys, Well, using shell script, I'm doing loop on DB query as below: isql -Usa -Ptest -I /opt/sybase/interfaces << EOF use testdb go declare @i int select @i = 1 while(@i <= 5) begin Insert into TEST values (@i,"Test","TestDesc") select @i = @i + 1 end go EOF The Issue... (2 Replies)
Discussion started by: Alaeddin
2 Replies
Login or Register to Ask a Question