The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reg :Executing a script through GUI . shyam.appalla Shell Programming and Scripting 2 05-30-2008 11:56 PM
Print out loop index on the console after executing each sybase DB query Alaeddin Shell Programming and Scripting 2 12-16-2007 04:30 AM
[AIX] executing script piooooter UNIX for Dummies Questions & Answers 1 05-26-2006 01:53 AM
executing script big123456 Shell Programming and Scripting 1 06-03-2005 08:32 AM
RSH use for executing a script frustrated1 Shell Programming and Scripting 6 10-02-2003 09:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2008
thumper thumper is offline VIP Member  
Supporter
  
 

Join Date: Feb 2005
Posts: 49
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 (permalink)  
Old 05-07-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
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
  #3 (permalink)  
Old 05-07-2008
thumper thumper is offline VIP Member  
Supporter
  
 

Join Date: Feb 2005
Posts: 49
Quote:
Originally Posted by robotronic View Post
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
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0