While Loop Logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While Loop Logic
# 1  
Old 08-30-2008
While Loop Logic

I would need to with making while loop logic working in shell program when I am new into the shell programing
1) I would need to try to get the file from the remote side ----need to try 15 mins apart for 4 times and terminate the program if file is not available....

I would need to know how I can setup counters to try in while loop ......

as I have sample at below. Please assist

==============================================
for file in $FILES; do
echo
echo "About to Retrieve $file from $SOU$SRDIR"
echo "via $proxy"
echo
err=1
while [ "$err" != 0 ]; do
ssh -x $proxy ftp "$SOU$SRDIR$file"
err=$?
if [ "$err" != 0 ]; then
echo "File transfer failed. Bummer. $err"
echo "Trying again in 15 minutes"
sleep 900
fi
done
echo " Retrieving file $file ..."
scp -p $proxy:~/$file .
chmod 666 $file
ls -l $file
ssh -x $proxy rm $file
done
==========================================
# 2  
Old 08-30-2008
syntex of while loop:
x=0;
while( $x -lt 10);do

steps;
x=x+1
done
# 3  
Old 08-31-2008
for file in $FILES
do
echo "About to Retrieve $file from $SOU$SRDIR"
echo "via $proxy"
err=1
cnt =1
while [ $cnt -le 4 ]
do
ssh -x $proxy ftp "$SOU$SRDIR$file"
err=$?
if [ "$err" != 0 ]
then
echo "File transfer failed. Bummer. $err"
echo "Trying again in 15 minutes"
sleep 900
cnt=`expr $cnt + 1`
else
break;
fi
done

echo " Retrieving file $file ..."
scp -p $proxy:~/$file .
chmod 666 $file
ls -l $file
ssh -x $proxy rm $file
done
# 4  
Old 08-31-2008
Or simply just

Code:
for attempts in one two three four;
  REMAINING=
  for file in $FILES; do
    echo
    echo "About to Retrieve $file from $SOU$SRDIR"
    echo "via $proxy"
    echo
    if ssh -x $proxy ftp "$SOU$SRDIR$file"; then
      echo " Retrieving file $file ..."
      scp -p $proxy:~/$file .
      chmod 666 $file
      ls -l $file
      ssh -x $proxy rm $file
    else
      echo "File transfer failed. Bummer. $err"
      echo "Trying again in 15 minutes"
      REMAINING="$REMAINING $file"
    fi
  done
  case $REMAINING in '') break;; esac
  FILES=$REMAINING
  sleep 900
done

# 5  
Old 09-02-2008
Thanks guys!

It works! You guys are very helpful.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell/Perl logic for loop

Hi, I have a requirement as follows. Have 3 files. Need to match up the data in each one of them and sum up the data by a field and display it. example given below. File 1 : Name, Emp id File 2 : Empid, Subject, File 3 : Subject, Score, Class Match Emp id in File 1 and File 2 and then... (7 Replies)
Discussion started by: preethgideon
7 Replies

2. Shell Programming and Scripting

while loop logic

Hi, Here I am trying to query database and check a value, if the value not matches then I wants to re-query the database.Once the value matches, I want to email the reqidstatus_log.txt file. Database query produces a file reqidstatus_log.txt which contains result. But the query not working as... (3 Replies)
Discussion started by: rajsp217
3 Replies

3. UNIX for Dummies Questions & Answers

if then else logic with while loop problem

Hi Friends, I have to do write a shell file based on one flag.If that flag value is 'N' then process look in $DATA are and the normal process continue.If vaule is 'P' then it check for the files in different location $CONV and move those file in $DATA area and rest of the process... (2 Replies)
Discussion started by: Param0073
2 Replies

4. Shell Programming and Scripting

loop logic inside of an inline redirect?

i need to log the feedback from the ftp server as i'm performing some deletes. the only way i know of to do this is with the inline redirect << EOF ... but from there to the closing EOF, it's like i'm at the ftp command prompt, so I don't know how to have ksh script logic in there I have an... (3 Replies)
Discussion started by: tlavoie
3 Replies

5. Shell Programming and Scripting

for loop logic with multiple parameters

hi, unix wizards, i have a question about the logic of my inner for loop below. first, what i am trying to do is to write a script called create_account that automatically creates mysql accounts. the user can provide a user_name or a group_id as an argument (and the script can take multiple... (1 Reply)
Discussion started by: ankimo
1 Replies
Login or Register to Ask a Question