Scrip to delete files older than 6 months
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
Setting up a cron job for once a month to start a script.
the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.
Looking to run this script once a month. Is that possible to get the old one deleted?
Please let me know if that isn't clear enough.
scripting ksh
add a comment |
up vote
8
down vote
favorite
Setting up a cron job for once a month to start a script.
the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.
Looking to run this script once a month. Is that possible to get the old one deleted?
Please let me know if that isn't clear enough.
scripting ksh
11
Why not just uselogrotate
?
– Michael Hampton
May 29 '13 at 20:33
@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45
Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54
@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Setting up a cron job for once a month to start a script.
the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.
Looking to run this script once a month. Is that possible to get the old one deleted?
Please let me know if that isn't clear enough.
scripting ksh
Setting up a cron job for once a month to start a script.
the script is to rotate a file each month as it gets too big and rename the old one. when a file is older than six months I wanted it to be deleted.
Looking to run this script once a month. Is that possible to get the old one deleted?
Please let me know if that isn't clear enough.
scripting ksh
scripting ksh
asked May 29 '13 at 20:29
scott marriott
54114
54114
11
Why not just uselogrotate
?
– Michael Hampton
May 29 '13 at 20:33
@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45
Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54
@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53
add a comment |
11
Why not just uselogrotate
?
– Michael Hampton
May 29 '13 at 20:33
@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45
Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54
@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53
11
11
Why not just use
logrotate
?– Michael Hampton
May 29 '13 at 20:33
Why not just use
logrotate
?– Michael Hampton
May 29 '13 at 20:33
@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45
@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45
Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54
Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54
@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53
@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53
add a comment |
2 Answers
2
active
oldest
votes
up vote
13
down vote
You could start with this:
find /your/file -mtime +182 -exec rm +
Where +182
are the days quantity.
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
@scottmarriott Not all versions offind
support+/-
for-mtime
. What OS and version offind
do you have?
– jordanm
May 30 '13 at 13:04
add a comment |
up vote
2
down vote
You can just use logrotate
. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
13
down vote
You could start with this:
find /your/file -mtime +182 -exec rm +
Where +182
are the days quantity.
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
@scottmarriott Not all versions offind
support+/-
for-mtime
. What OS and version offind
do you have?
– jordanm
May 30 '13 at 13:04
add a comment |
up vote
13
down vote
You could start with this:
find /your/file -mtime +182 -exec rm +
Where +182
are the days quantity.
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
@scottmarriott Not all versions offind
support+/-
for-mtime
. What OS and version offind
do you have?
– jordanm
May 30 '13 at 13:04
add a comment |
up vote
13
down vote
up vote
13
down vote
You could start with this:
find /your/file -mtime +182 -exec rm +
Where +182
are the days quantity.
You could start with this:
find /your/file -mtime +182 -exec rm +
Where +182
are the days quantity.
edited May 29 '13 at 20:46
jordanm
29.9k28192
29.9k28192
answered May 29 '13 at 20:41
ramonovski
32217
32217
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
@scottmarriott Not all versions offind
support+/-
for-mtime
. What OS and version offind
do you have?
– jordanm
May 30 '13 at 13:04
add a comment |
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
@scottmarriott Not all versions offind
support+/-
for-mtime
. What OS and version offind
do you have?
– jordanm
May 30 '13 at 13:04
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
Thanks for that, might have a play with it, but I maybe logrotate might be the best option
– scott marriott
May 29 '13 at 20:55
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
@jordanm any ideas why this might not of worked?
– scott marriott
May 30 '13 at 9:51
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
ApplicationServer/logs/TestClone01 $ ls -ltr total 3320 1048458 13 Dec 09:46 SystemOut_12.12.13_09.46.29.log 28 May 12:44 SystemOut.log.2013-05-28-12:44:52 71 30 May 08:57 SystemOut.log.2013-05-30-08:57:22 48432 30 May 09:16 SystemOut.log no_env):/usr/websphere6/was61TE_LV2/ApplicationServer/logs/TestClone01 $ find SystemOut.log -mtime +1 -exec rm + find: 0652-083 Cannot execute :: A file or directory in the path name does not exist.
– scott marriott
May 30 '13 at 9:53
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
I changed number of days to 1
– scott marriott
May 30 '13 at 10:09
@scottmarriott Not all versions of
find
support +/-
for -mtime
. What OS and version of find
do you have?– jordanm
May 30 '13 at 13:04
@scottmarriott Not all versions of
find
support +/-
for -mtime
. What OS and version of find
do you have?– jordanm
May 30 '13 at 13:04
add a comment |
up vote
2
down vote
You can just use logrotate
. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.
add a comment |
up vote
2
down vote
You can just use logrotate
. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.
add a comment |
up vote
2
down vote
up vote
2
down vote
You can just use logrotate
. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.
You can just use logrotate
. It's already available on most Linux systems, and many packages already have logrotate scripts pre-configured, or you can tweak them or write your own.
answered May 30 '13 at 18:56
Michael Hampton
5,52911740
5,52911740
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f77558%2fscrip-to-delete-files-older-than-6-months%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
11
Why not just use
logrotate
?– Michael Hampton
May 29 '13 at 20:33
@scottmarriott yeah, Mr Hampton's right, the functionality you described is basically the exact thing logrotate does.
– Bratchley
May 29 '13 at 20:45
Yeah I've just had a good look at logrotate makes sense cheers all
– scott marriott
May 29 '13 at 20:54
@MichaelHampton you should make that an answer.
– evilsoup
May 30 '13 at 18:53