procmail
[Top] [All Lists]

Re: Automatically Deleting Based on Date

1996-10-24 21:14:05
    > Brock Rozen wrote:
    > >         :0:
    > >         * $ ^From: majordomo$PGHOST
    > >         * ^Subject: (Majordomo results:) .* (who)
    > >         PG/Backup-`date +%m-%d`
    > > 
    > > I haven't figured out how to have it delete the previous folder
    > > automatically. These messages are received (if everything works out) 
once
    > > a day. Thus, the previous folder is the day before.
    > 
    > The following may not be pretty, but I believe (knock wood) that it
    > should work.  The date command is capable of generating a date
    > /relative/ to today.  So, in order to delete yesterday's folder,
    > you could simply add the following to your action:
    >     rm -f PG/Backup-`date -d '-1 day' +'%M-%d'`;
    > Using the -f option of rm means that the file will be removed without
    > error -- whether or not it exists, and the date will append the
    > appropriate suffix to the filename to delete yesterday's file.

Uh, which version of "date" are you using?  Perhaps GNU date does
this, but not most "standard" vendor date commands.

Another way to get the previous folder is to let "ls" tell you.
If you using a naming algorithm which sorts intuitively, then
the last folder less one should be the previous folder.

This procmail command should remove the next to last file:

    JUNK=`ls -1 PG/Backup-* | tail -2 | head -1 | xargs rm -f`

    :0c:
    * $ ^From: majordomo$PGHOST
    * ^Subject: Majordomo results: .* who
    PG/Backup-`date +%m-%d`

    :0A
    JUNK=|ls -1 PG/Backup-* | tail -2 | head -1 | xargs rm -f

___________________________________________________________
Alan Stebbens <aks(_at_)sgi(_dot_)com>      http://reality.sgi.com/aks

<Prev in Thread] Current Thread [Next in Thread>