Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find if a Command was succesfull

Status
Not open for further replies.

nogs

Technical User
Aug 3, 2001
89
GB
This is a command I have in a script;

find . -type f -mtime -1 -exec rcp {} $SITE:$REMDIR \

What I would like is a way of knowing if any files were actually copied
 
Before your find you could check how many files exist in
the remote directory eg count1=`ls|wc -l`
and after the find do count2=`ls|wc -l`
then compare the 2 counts
DB :)
Dickie Bird
db@dickiebird.freeserve.co.uk
 
DB
That could work - my only problem is that as the files are from an external source I cant guarantee they will be unique, obvioulsy if a file is then overwritten the file count wouldnt go up

Thanks for your help though

Nogs
 
Nogs:

You can do radical surgery to your find command and rcp each file, and check the exit code. I think you'd lose efficiency doing this sort of thing, but ....

for file in `find . -type f -mtime -1 -print`
do
rcp $file $SITE:$REMDIR
if [ "$?" eq - ] ; then
.
.
done


Regards,

Ed

 
You could clear the current directory first
(save all files to a sub-directory, perhaps )
and do the wc -l command afterwards ??????
DB
:) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Or:
Code:
find . -type f -mtime -1 | xargs -i sh -c "
    rcp {} $SITE:$REMDIR
    if [ $? -eq 0 ] ; then
        echo '{} OK'
    fi
"
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top