![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 ========================================== |
|
||||
|
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 |
|
||||
|
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
|
![]() |
| Bookmarks |
| Tags |
| while loop logic |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|