The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Using variables created sequentially in a loop while still inside of the loop [bash] DeCoTwc Shell Programming and Scripting 2 06-23-2009 04:59 PM
Is there a better way I could have run this loop. (For loop with two variables) DeCoTwc Shell Programming and Scripting 2 03-27-2009 02:07 AM
while loop inside while loop panknil Shell Programming and Scripting 0 01-07-2008 12:49 PM
For Loop knc9233 UNIX for Dummies Questions & Answers 6 01-12-2007 09:55 PM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 11:09 AM

Reply
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 07-20-2009
sigh2010 sigh2010 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 21
while loop with 3 ifs

im messing up somehwere...and can't seem to clean up the script...for it to work

objectives:

1. check for today's file, and sleep 30 secs between retries
2. only allow 5 tries before script should fail.
3. if today's file found, wait 30 seconds for it to process..


code:

Code:
count=0
while [ $count -lt 5 ]
do
    count=`expr $count + 1`
    echo "Try $count"
    RUNDATE=`date "+%h%e"`
    filedate=`ls -l file.xml | awk '{print $6,$7}`
    if [ $count -ge 5 ]
      echo "Too many retries"
      echo "Please check source why the file is not imported"
       exit 0
    else           
     if [ "$filedate" = "$RUNDATE" ] 
     echo "Today's file is ready for processing."
         echo "Sleeping 30 secs to allow it to process "
      sleep 30
           break
     fi
    fi
    if [ "$filedate" != "$RUNDATE" ]
      echo "File date in directory is $filedate and today's date is $RUNDATE. They don't match"
  echo "Sleeping 30 seconds and trying again; 5 tries is my limit"
          sleep 30
    fi
done

Last edited by vgersh99; 07-20-2009 at 04:31 PM.. Reason: code tags, PLEASE!
Bits Awarded / Charged to sigh2010 for this Post
Date User Comment Amount
07-20-2009 vgersh99 added code tags - charged 3K bits -3,000
  #2 (permalink)  
Old 07-20-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
  #3 (permalink)  
Old 07-21-2009
sigh2010 sigh2010 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 21
Can someone assist please?
  #4 (permalink)  
Old 07-21-2009
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Quote:
count=`expr $count + 1`
this is the if - else construct

Code:
if [ $count -eq 2 ]
then
echo "yes"
else
echo "no"
fi
missing ' then '
  #5 (permalink)  
Old 07-21-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Code:
 if [ $count -ge 5 ]; then
is the correct syntax.
  #6 (permalink)  
Old 07-21-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Btw, if you use sed -x to debug, life would be easy.
  #7 (permalink)  
Old 07-21-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,421
Quote:
Originally Posted by sigh2010 View Post
Code:
count=0
while [ $count -lt 5 ]
do
    count=`expr $count + 1`
    echo "Try $count"
count will never get greater that 4, first if is not required.

Quote:
Originally Posted by sigh2010 View Post
Code:
   RUNDATE=`date "+%h%e"`
    filedate=`ls -l file.xml | awk '{print $6,$7}`
$RUNDATE and $filedate will never match here, check why.
Reply

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 01:03 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