PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > shell script to compare and delete files from a server???
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

shell script to compare and delete files from a server???

Réponse
 
LinkBack Outils de la discussion
Vieux 18/08/2006, 08h48   #1
Danish
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut shell script to compare and delete files from a server???

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


Thanks
Danish

  Réponse avec citation
Vieux 18/08/2006, 08h50   #2
Danish
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???


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...
>
>
> Thanks
> Danish


Forgot to add
> 2) Only B can access A using the shell. A cannot access B. The access is possible using ssh


  Réponse avec citation
Vieux 18/08/2006, 09h13   #3
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???

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


You may want to check "rsync", which pretty much does most of the stuff
you want. try google or man rsync.

Good luck,
Xicheng

  Réponse avec citation
Vieux 18/08/2006, 10h48   #4
aarcee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???

Yes , rsyncis one option. Also if the public keys are shared between A
and B , then
you can do this thru a script.

Some thing like . From node B> ssh A `ls filename`

It will return a value if it matches , the same way you can compare the
bytes

Thx
RC
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...
>
>
> Thanks
> Danish


  Réponse avec citation
Vieux 18/08/2006, 13h13   #5
Jon LaBadie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???

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 ...
  Réponse avec citation
Vieux 18/08/2006, 14h27   #6
Danish
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???


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

Danish

  Réponse avec citation
Vieux 18/08/2006, 19h53   #7
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: shell script to compare and delete files from a server???

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

  Réponse avec citation
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
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h37.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17902 seconds with 16 queries