Afficher un message
Vieux 19/08/2006, 10h48   #8
Danish
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???


Xicheng Jia wrote:
> Danish wrote:
> > Jon LaBadie wrote:
> > > Danish wrote:
> > > > Danish wrote:
> > > >> Hi,
> > > >> I just got this script to write from my boss, but I thought I should
> > > >> discuss my problem here too.
> > > >>
> > > >> Ive got this situation where:
> > > >> 1) There are 2 server's ( A & B) located at quite a distance from each
> > > >> other..
> > > >>
> > > >> 2) Only B can access A using the shell. A cannot access B.
> > > >>
> > > >> 3) There is a perl script on B which runs every hour. It downloads
> > > >> certain files from another remote server using ftp. When these files
> > > >> have been downloaded comepletely they are 'scp'd to A using a shell
> > > >> script.
> > > >>
> > > >> Now I have been told to:
> > > >> 1) Make a shell script in B, to compare, whether the downloaded files
> > > >> in B have been completely 'scp'd to A.
> > > >> 2) When the comparing has been done, giving a result that the files are
> > > >> same on both the servers, the script then should delete the downloaded
> > > >> files from B
> > > >>
> > > >> Frankly speaking, I am confused as to how to go about comparing the
> > > >> files...
> > > >>
> > >
> > > presumably you have a list of files on B that supposedly were
> > > already uploaded to A. Use that list to generate "checksums"
> > > of each of the files on each host. Compare the checksums and
> > > if they match, the files on the two systems are identical.
> > >
> > > You really should also do this on the original source host,
> > > before it gets to B to ensure the file has been received on
> > > B accurately before uploading to A.
> > >
> > > Programs that do checksums include sha1sum, md5sum, cksum.
> > >
> > > The files on A can be determined with ssh from B:
> > >
> > > ssh A sha1sum file1 file2 file3 ...

> >
> > I spoke to my boss regarding the checksum, but he does not want it that
> > way...So ill have to think of some other way

>
> If you just want to get the status instead of updating files, with the
> full-featured 'rsync':
> 1) no need to transfer files, with the option -n or --dry-run
> 2) use ssh/key-pairs with option like -e "ssh -i /path/to/.ssh/id_dsa
> user@host"
> 3) skip files based on checksum, not mtime/size with the option -c,
> --checksum (MD4 with my current rsync version).
> .......
> you may also want the option -av to return more info and then parse it.
>
> Xicheng


Thanks for the rysnc, but as I had said, He does not want to use rsync,
so I cant. But I made a shell script with array's wherein:
1) Im doing `ls -l` on the dir and cutting the file size.
2) Feeding the output of `ls -l` into an array
3) Doing ssh remote_host "ls -l /path/to/files" and then feeding it
into an array

Im trying to compare the values of the two arrays, and if the the size
of each file is equal Ill put in the `rm`command to delete the files
from the local host..

Ive been able to feed the output into the array, but am not able to
figure out how to compare the value of the arrays....

Would like to have your advise on it....

#!/bin/sh



array=(`ls -l /home/danish/scp | tr -s " " | cut -d " " -f5`)

len=${#array[*]}


i=0

while [ $i -lt $len ]; do
echo "${array[$i]}"
let i++
done

echo "ssh to 192.168.10.98 starts here"

array1=`ssh 192.168.10.98 " vdir /home/danish/scp/* | tr -s \"
\"|cut -d \" \" -f5 "`

length=${#array1[*]}

j=0

while [ $j -lt $length ]; do
echo "${array1[$j]}"
let j++
done


Thanks
Danish

  Réponse avec citation
 
Page generated in 0,07247 seconds with 9 queries