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
If Then Else Logic jadionne UNIX for Dummies Questions & Answers 7 11-23-2007 04:27 AM
cannot get the logic dineshr85 Shell Programming and Scripting 3 10-11-2007 07:34 AM
expand logic for > and < pbsrinivas Shell Programming and Scripting 0 08-10-2007 09:59 AM
Need help in genrating the logic amitjha Shell Programming and Scripting 6 11-08-2006 06:45 AM
what the logic ramneek IP Networking 2 09-05-2005 07:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2008
sambakamba sambakamba is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
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 (permalink)  
Old 08-30-2008
RahulJoshi's Avatar
RahulJoshi RahulJoshi is offline
Registered User
  
 

Join Date: Aug 2008
Location: PUNE
Posts: 98
syntex of while loop:
x=0;
while( $x -lt 10);do

steps;
x=x+1
done
  #3 (permalink)  
Old 08-31-2008
rajamohan rajamohan is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
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 (permalink)  
Old 08-31-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 (permalink)  
Old 09-02-2008
sambakamba sambakamba is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 5
Thanks guys!

It works! You guys are very helpful.
Closed Thread

Bookmarks

Tags
while loop logic

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 10:20 PM.


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