|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|