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 > Comparison of two files based on timestamp
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Comparison of two files based on timestamp

Réponse
 
LinkBack Outils de la discussion
Vieux 07/03/2007, 13h28   #1
Sandy80
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Comparison of two files based on timestamp

Hi,

I have a script that ftpes some files from one server everyday. It has
a version of the same file that was ftped yesterday. Once the ftp is
over to take care of the case where the file might not be available
today it checks which is the older file and deletes that version of
the file so that only the newest exists.

So it would do
rm_filenm_12=`ls STRUCTURE-AM.FULL*IS*.dat | head -1`
rm $rm_filenm_12

This is working fine and removes the older version of the file.
But I am trying to introduce some new files for which I am trying to
put the same logic:

rm_filenm_16=`ls SERVICES-AM.FULL*.dat | head -1`
rm $rm_filenm_16

But here the command behaves exactly the opposite and removes the
latest file which means the older files exists. Also I have made sure
that files have different timestamps and the older file is one day old
but still the same issue.

can anyone advice me as to what could be the issue here or is there
something that I might be doing wrong which I need to check for.

Thanks,
Sandy

  Réponse avec citation
Vieux 07/03/2007, 13h37   #2
swami
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Comparison of two files based on timestamp

You can try using

find -newer <timestamp>

option for this.

swami.



On Mar 7, 5:28 pm, "Sandy80" <svarshneym...@gmail.com> wrote:
> Hi,
>
> I have a script that ftpes some files from one server everyday. It has
> a version of the same file that was ftped yesterday. Once the ftp is
> over to take care of the case where the file might not be available
> today it checks which is the older file and deletes that version of
> the file so that only the newest exists.
>
> So it would do
> rm_filenm_12=`ls STRUCTURE-AM.FULL*IS*.dat | head -1`
> rm $rm_filenm_12
>
> This is working fine and removes the older version of the file.
> But I am trying to introduce some new files for which I am trying to
> put the same logic:
>
> rm_filenm_16=`ls SERVICES-AM.FULL*.dat | head -1`
> rm $rm_filenm_16
>
> But here the command behaves exactly the opposite and removes the
> latest file which means the older files exists. Also I have made sure
> that files have different timestamps and the older file is one day old
> but still the same issue.
>
> can anyone advice me as to what could be the issue here or is there
> something that I might be doing wrong which I need to check for.
>
> Thanks,
> Sandy



  Réponse avec citation
Vieux 07/03/2007, 16h10   #3
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Comparison of two files based on timestamp

Sandy80 wrote:
> Hi,
>
> I have a script that ftpes some files from one server everyday. It has
> a version of the same file that was ftped yesterday. Once the ftp is
> over to take care of the case where the file might not be available
> today it checks which is the older file and deletes that version of
> the file so that only the newest exists.
>
> So it would do
> rm_filenm_12=`ls STRUCTURE-AM.FULL*IS*.dat | head -1`
> rm $rm_filenm_12
>
> This is working fine and removes the older version of the file.
> But I am trying to introduce some new files for which I am trying to
> put the same logic:
>
> rm_filenm_16=`ls SERVICES-AM.FULL*.dat | head -1`
> rm $rm_filenm_16
>
> But here the command behaves exactly the opposite and removes the
> latest file which means the older files exists. Also I have made sure
> that files have different timestamps and the older file is one day old
> but still the same issue.
>
> can anyone advice me as to what could be the issue here or is there
> something that I might be doing wrong which I need to check for.
>


ls does alphabetic sorting,
so ls | head -1
is the filename that is first in the alphabet.

ls -tr | head -1
is the name of the oldest file.

--
Michael Tosch @ hp : com
  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 22h46.


Édité par : vBulletin® version 3.7.3
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 ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08633 seconds with 11 queries