Hi All
AIX 5.3
We have a clean up script to backup and remove files. The script run
at 4:00am daily.
When Change Month to 1st, some file will not backup and remove. Any
suggestion ?
YEAR=`date +%y`
MON=`date +%m`
.....
cd $SATEDIR
echo
pkzip -x *.zip -u ${YEAR}${MON}sate ??${MON}* ${MON}*.log
find . -name "??${MON}*" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
find . -name "${MON}*.log" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
|
|
0
|
|
|
|
Reply
|
moonhkt
|
11/24/2010 2:42:46 AM |
|
In article
<431a2d34-e1f1-4839-85ca-bec5edf98340@s11g2000prs.googlegroups.com>,
moonhkt <moonhkt@gmail.com> wrote:
> Hi All
>
> AIX 5.3
>
> We have a clean up script to backup and remove files. The script run
> at 4:00am daily.
> When Change Month to 1st, some file will not backup and remove. Any
> suggestion ?
What does "Change Month to 1st" mean? Do you mean the script doesn't
work in January?
>
> YEAR=`date +%y`
> MON=`date +%m`
>
> ....
> cd $SATEDIR
> echo
> pkzip -x *.zip -u ${YEAR}${MON}sate ??${MON}* ${MON}*.log
> find . -name "??${MON}*" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
> find . -name "${MON}*.log" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
0
|
|
|
|
Reply
|
Barry
|
11/24/2010 1:27:37 PM
|
|
On Nov 24, 9:27=A0pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article
> <431a2d34-e1f1-4839-85ca-bec5edf98...@s11g2000prs.googlegroups.com>,
>
> =A0moonhkt <moon...@gmail.com> wrote:
> > Hi All
>
> > AIX 5.3
>
> > We have =A0a clean up script to backup and remove files. The script run
> > at 4:00am daily.
> > When Change Month to 1st, some file will not backup and remove. Any
> > suggestion ?
>
> What does "Change Month to 1st" mean? =A0Do you mean the script doesn't
> work in January?
>
>
>
> > YEAR=3D`date +%y`
> > MON=3D`date +%m`
>
> > ....
> > cd $SATEDIR
> > echo
> > pkzip -x *.zip -u ${YEAR}${MON}sate ??${MON}* ${MON}*.log
> > find . -name "??${MON}*" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
> > find . -name "${MON}*.log" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
No, will current date change to first day of each month.
e.g.
??1101.log created on Nov 1
??1130.log created on Nov 30
??1201.log created on Dec 1
When current date change to Dec 1, file created on Nov 1 will not zip
and remove.
|
|
0
|
|
|
|
Reply
|
moonhkt
|
11/24/2010 2:32:23 PM
|
|
On 2010-11-24, moonhkt <moonhkt@gmail.com> wrote:
> On Nov 24, 9:27 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
>> In article
>> <431a2d34-e1f1-4839-85ca-bec5edf98...@s11g2000prs.googlegroups.com>,
>>
>> moonhkt <moon...@gmail.com> wrote:
>> > Hi All
>>
>> > AIX 5.3
>>
>> > We have a clean up script to backup and remove files. The script run
>> > at 4:00am daily.
>> > When Change Month to 1st, some file will not backup and remove. Any
>> > suggestion ?
>>
>> What does "Change Month to 1st" mean? Do you mean the script doesn't
>> work in January?
>>
>>
>>
>> > YEAR=`date +%y`
>> > MON=`date +%m`
>>
>> > ....
>> > cd $SATEDIR
>> > echo
>> > pkzip -x *.zip -u ${YEAR}${MON}sate ??${MON}* ${MON}*.log
>> > find . -name "??${MON}*" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
>> > find . -name "${MON}*.log" ! -name "*.zip" -mtime +7 -exec rm -f {} \;
>>
>
> No, will current date change to first day of each month.
> e.g.
> ??1101.log created on Nov 1
> ??1130.log created on Nov 30
> ??1201.log created on Dec 1
>
> When current date change to Dec 1, file created on Nov 1 will not zip
> and remove.
Because you told it to only zip and remove files whose name matches the
current month. Either set a variable with the previous month number,
and the previous year if the previous month is December, or use
find -mtime instead.
--
Year, n.:
A period of three hundred and sixty-five disappointments.
-- Ambrose Bierce, "The Devil's Dictionary"
|
|
0
|
|
|
|
Reply
|
Bill
|
11/25/2010 9:04:34 AM
|
|
moonhkt <moon...@gmail.com> wrote:
> ...
> AIX 5.3
My consolations. Fortunately, it doesn't much affect shell scripting.
> YEAR=`date +%y`
> MON=`date +%m`
Just an aside:
http://cfajohnson.com/shell/tuesday-tips/#tt-2004-06-29
That is:
eval $(date '+YEAR=%y MON=%m')
Sure it's just one less process, but it can scale up to save 33...
theoretically.
BTW, does the following code help you?
http://cfajohnson.com/shell/tuesday-tips/#tt-2004-06-16
Or, If you don't need to restore backups by year-month-day info,
why not just index the backups by their Julian Day Number? Or
better yet, what _I_ would do is:
# a bad Y2K experience makes me want 4-digit year numbers
eval date +file_index=%Y-%W-%j
So, to delete all the backups for this week:
rm 2010-49-?? # this is the 49th week of the year, right?
(I hope your date(1) under A/IX has these options
implemented).
Using the find(1) -mtime option is less work and the best
technique, but the techniques of integral manipulation of JDNs
or using the appropriate shell patterns to determine date ranges,
as shown above, is at least straightforward.
=Brian
|
|
0
|
|
|
|
Reply
|
bsh
|
12/1/2010 3:38:52 AM
|
|
|
4 Replies
794 Views
(page loaded in 0.084 seconds)
|