If loop not ending


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If loop not ending
# 1  
Old 06-05-2013
If loop not ending

Hi,

The first if loop in the script not ending and going to infinite loop.

Code:
#!/usr/bin/ksh
set -vx
lc=1
st_date=$(date "+%Y%m%d")
LOGFILE=/home/infa_shared/OM_ftp_transfer.log.$st_date
file="/home/infa_shared/OM_WF.log.$st_date"
while [[ ! -f "$file"  ]]; do
if [[ $lc -lt 15 ]]
then
  sleep 15
  let lc=lc+1
print "Waiting for flow.dat file  for $lc minutes " >> $LOGFILE
   if [ -f "$file" ]
then
        echo "$file found.Transfering flow.dat dummy file at $(date)" >> $LOGFILE
        cd /home/infa_shared/
        echo "File created" >> $LOGFILE
        touch flow.dat
        chmod 777 om_flow.dat
        echo "FTP Process Started" >> $LOGFILE
        cp /home/infa_shared/OM_WORKFLOW.netrc $HOME/.netrc
        chmod 700 $HOME/.netrc
        ftp zwg47nix3v.comm.com
        rm $HOME/.netrc
        echo "FTP Process Completed" >> $LOGFILE
        rm flow.dat
        echo "File flow.dat deleted" >> $LOGFILE
        exit
      fi
fi
done

if [[ $lc -eq 15 ]]
then
print "Waited for 15 min for om_workflow.dat file" >> $LOGFILE
exit
fi

if [ -f "$file" ]
then
        echo "$file found.Transfering flow.dat dummy file at $(date)" >> $LOGFILE
        cd /home/infa_shared/
        echo "File created" >> $LOGFILE
        touch flow.dat
        chmod 777 flow.dat
        echo "FTP Process Started" >> $LOGFILE
        cp /home/infa_shared/OM_WORKFLOW.netrc $HOME/.netrc
        chmod 700 $HOME/.netrc
         ftp zwg47nix3v.comm.com
        rm $HOME/.netrc
        echo "FTP Process Completed" >> $LOGFILE
        rm flow.dat
        echo "File flow.dat deleted" >> $LOGFILE
              exit
        fi

debugging log -

Code:
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]


If I gave condition eq it going infinite loop from starting.If less than given it waiting for 14 min after 15 its going to infinite loop

Thanks in advance
# 2  
Old 06-05-2013
Quote:
Originally Posted by nag_sathi
The first if loop in the script not ending and going to infinite loop.



Code:
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]
+ [[ ! -f /home/infa_shared/OM_WF.log.20130605 ]]
+ [[ 15 -lt 15 ]]

You have problem with while. as while loop is not ending.
Please change conditions in while loop.
# 3  
Old 06-05-2013
Hi Pamu,

Thanks for reply

The main aim of this code is to check for a file, if not exist it have to wait 15 min for that file, later on it needs to come out of this while loop and execute another if loop(2nd) then log a msg. I am not sure why while loop not ending.
# 4  
Old 06-05-2013
Quote:
Originally Posted by nag_sathi
Hi Pamu,

Thanks for reply

The main aim of this code is to check for a file, if not exist it have to wait 15 min for that file, later on it needs to come out of this while loop and execute another if loop(2nd) then log a msg. I am not sure why while loop not ending.
I would advise to you to start use of functions in the script.

Code:
while [[ ! -f "$file"  ]]; do
if [[ $lc -lt 15 ]]
then
  sleep 15  # this should 60 as it is in seconds
  let lc=lc+1
print "Waiting for flow.dat file  for $lc minutes " >> $LOGFILE
   if [ -f "$file" ]
then
        echo "$file found.Transfering flow.dat dummy file at $(date)" >> $LOGFILE
        cd /home/infa_shared/
        echo "File created" >> $LOGFILE
        touch flow.dat
        chmod 777 om_flow.dat
        echo "FTP Process Started" >> $LOGFILE
        cp /home/infa_shared/OM_WORKFLOW.netrc $HOME/.netrc
        chmod 700 $HOME/.netrc
        ftp zwg47nix3v.comm.com
        rm $HOME/.netrc
        echo "FTP Process Completed" >> $LOGFILE
        rm flow.dat
        echo "File flow.dat deleted" >> $LOGFILE
        exit
      fi
else
# do your second check as 15 minutes are already over when it comes to else part.
fi
done

you can add else part for the above loop.
This User Gave Thanks to pamu For This Post:
# 5  
Old 06-05-2013
I think you want
Code:
while [[ ! -f "$file"  ]] && [[ $lc -lt 15 ]]; do
  sleep 60
  let lc=lc+1
done
if [[ -f "$file ]]
then
  ...
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Ending Spam and Etc.

This is a very general question but the idea popped into my head several years ago and wanted the opinions of all the master jedi's of this forum. I had a client that no matter what was done to control there spam(spam assassin,anti-virus(email scanning) and etc) sooner or later something would slip... (2 Replies)
Discussion started by: metallica1973
2 Replies

2. Shell Programming and Scripting

Remove ending text

Hello, I am working with a list that contains a large number of files listed by their absolute path. I am trying to determine a way to delete the file name at the end of each line, therefore leaving just the directory path. For example, I'd like to go from: /home/something/file... (2 Replies)
Discussion started by: omnivir
2 Replies

3. Shell Programming and Scripting

Nested for loop not ending

Hi All, Need help on below script for g in `cat /home/sid.txt` do for h in `cat /home/dev.txt` do symmaskdb -sid $g -dev $h list assign |grep FA |head -1|awk '{print $2}' > tt1.txt done done cat /home/sid.txt ************** 123 235 456 (5 Replies)
Discussion started by: ranjancom2000
5 Replies

4. SCO

File name ending with @

Hi Current SCO Unix 5.05 I see that there are filenames with @ at the end of file name for example in the /usr/lib there is file lpadmin@ what does the @ represent when it is at the end of the file name Thanks (4 Replies)
Discussion started by: atish0
4 Replies

5. Shell Programming and Scripting

Ending a script

Hi all, I am trying to end a Menu script. Can people suggest various methods please? At the moment I am doing: quit=n while do ...Code Code Code... read userinput case $userinput in q|Q) quit=y;; esac done But this doesn't seem to work every time, occasionally it will work,... (6 Replies)
Discussion started by: mikejreading
6 Replies

6. Shell Programming and Scripting

never ending loop

Guys I have a script like the one below. One script executes another script in a loop. but i want the other script within the main script to be executed only 3 times. the script within the main script again references the main script after its execution. plz help. while } ] do... (21 Replies)
Discussion started by: ragha81
21 Replies

7. Programming

executables ending with *

Hi All, I m very new to unix. I have a basic doubt .. In unix I m seeing that there is a * at the end of by executable name (exe1*).. Wht is the significance of that Thanks a lot in advance (2 Replies)
Discussion started by: binums
2 Replies

8. UNIX for Dummies Questions & Answers

File- Ending

Hi folks! I'm new in this forum and in the UNIX-world too!! I've got a real problem: I have to read out datas like name and e-mail-adress from a Windows- Server from the active directory and put this information into a file. This file should be moved (or copied) on a Unix- Server... But I... (3 Replies)
Discussion started by: spikylina
3 Replies

9. UNIX for Dummies Questions & Answers

Ending Mail

hello, I a problem. I would like write script in True64 Unix.see below. last testerkl | head > mailfile.asc wolteru < mailfile.asc With the "last" command I get a list when testerkl logged on. And I would like to send this to a user. But how can I write in a "ctrl.-d" and "ctrl.-c" that... (2 Replies)
Discussion started by: Peterh
2 Replies
Login or Register to Ask a Question