The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
copy command failure mynix Shell Programming and Scripting 1 12-15-2007 09:35 PM
telnet failure billet75 AIX 3 08-14-2007 01:09 PM
Unzip, copy, and delete loop spyne Shell Programming and Scripting 3 03-07-2007 10:30 AM
ld failure handak9 High Level Programming 2 09-29-2004 07:56 AM
CPU failure??? 98_1LE UNIX for Dummies Questions & Answers 1 01-23-2001 02:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-10-2007
Registered User
 

Join Date: Jul 2007
Location: Cloud 9
Posts: 70
while loop to copy on failure

I'm trying to do an automated SCP (passwordless auth is already set up) from a bash script...

My problem is that on the receiving end, the computer will sometimes NOT actually get my files. BUT if I loop enough times (by hand at the moment) calling an 'ls' on those files, I can see if the files got there, otherwise resend.

This works, believe it or not... maybe somethings screwed up with my SCP?

Either way, I want to now put this functionality into a script, so I can just get the 'ls' of my files, see if there are 4 lines (pre-grepped for just files, no headers) -- aka 4 files -- and if there are, continue... else loop.

Pseudo-code:
Code:
do {
  scp veryOriginalName.1 root@myComp:/tmp
  scp veryOriginalName.2 root@myComp:/tmp
  scp veryOriginalName.3 root@myComp:/tmp
  scp veryOriginalName.4 root@myComp:/tmp

  VAR = ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l
} while {
  VAR != 4
}
Reply With Quote
Forum Sponsor
  #2  
Old 12-10-2007
Registered User
 

Join Date: Dec 2007
Posts: 6
Red face

Quote:
Originally Posted by jjinno View Post
I'm trying to do an automated SCP (passwordless auth is already set up) from a bash script...

My problem is that on the receiving end, the computer will sometimes NOT actually get my files. BUT if I loop enough times (by hand at the moment) calling an 'ls' on those files, I can see if the files got there, otherwise resend.

This works, believe it or not... maybe somethings screwed up with my SCP?

Either way, I want to now put this functionality into a script, so I can just get the 'ls' of my files, see if there are 4 lines (pre-grepped for just files, no headers) -- aka 4 files -- and if there are, continue... else loop.

Pseudo-code:
Code:
do {
  scp veryOriginalName.1 root@myComp:/tmp
  scp veryOriginalName.2 root@myComp:/tmp
  scp veryOriginalName.3 root@myComp:/tmp
  scp veryOriginalName.4 root@myComp:/tmp

  VAR = ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l
} while {
  VAR != 4
}

If I understand the problem correctly , for kourne-shell, can do something like below:

#!/bin/ksh

file_cntr=0
while [[ $file_cntr != 4 ]]; do
# do copy file
scp ...

# do get file_cntr value
file_cntr=`ssh root@myComp "ls -l ...`
done
Reply With Quote
  #3  
Old 12-10-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by jjinno View Post
Code:
do {
  scp veryOriginalName.1 root@myComp:/tmp
  scp veryOriginalName.2 root@myComp:/tmp
  scp veryOriginalName.3 root@myComp:/tmp
  scp veryOriginalName.4 root@myComp:/tmp

  VAR = ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l
} while {
  VAR != 4
}
Why not use the error code returned by scp to indicate the success or failure of the operation?

Also, you can transfer multiple at the same time which would save time on connection and negotiation....

Code:
scp veryOriginalName.1 \
       veryOriginalName.2 \
       veryOriginalName.3 \
       veryOriginalName.4 root@myComp:/tmp/
if test "$?" = "0"
then
     echo success
     VAR = `ssh root@myComp "ls -l /tmp/veryOriginalName.*" | grep "-" | wc -l`
else
     echo failure
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0