Is my cron command good? [closed]

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I try to clean the logs once a week with this cron command:
@weekly find /var/log/ ( -iregex ".*.[2-20]+" -o -iname "*.gz" ) -exec rm ; 2>&1
Is it good?
ubuntu cron
closed as primarily opinion-based by Jesse_b, G-Man, Jeff Schaller, nwildner, Romeo Ninov May 10 at 19:13
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
0
down vote
favorite
I try to clean the logs once a week with this cron command:
@weekly find /var/log/ ( -iregex ".*.[2-20]+" -o -iname "*.gz" ) -exec rm ; 2>&1
Is it good?
ubuntu cron
closed as primarily opinion-based by Jesse_b, G-Man, Jeff Schaller, nwildner, Romeo Ninov May 10 at 19:13
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
4
Is there a reason you're doing this rather than using a log rotation daemon?
â DopeGhoti
May 9 at 21:33
@DopeGhoti No particular reason, I'll find out.
â c.bruno
May 10 at 9:07
What does âÂÂgoodâ mean in this context? It invites âÂÂyesâ or âÂÂnoâ answers. Does it remove all and only the files you want?
â Jeff Schaller
May 10 at 10:11
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to clean the logs once a week with this cron command:
@weekly find /var/log/ ( -iregex ".*.[2-20]+" -o -iname "*.gz" ) -exec rm ; 2>&1
Is it good?
ubuntu cron
I try to clean the logs once a week with this cron command:
@weekly find /var/log/ ( -iregex ".*.[2-20]+" -o -iname "*.gz" ) -exec rm ; 2>&1
Is it good?
ubuntu cron
edited May 9 at 21:35
Iskustvo
667118
667118
asked May 9 at 21:00
c.bruno
234
234
closed as primarily opinion-based by Jesse_b, G-Man, Jeff Schaller, nwildner, Romeo Ninov May 10 at 19:13
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as primarily opinion-based by Jesse_b, G-Man, Jeff Schaller, nwildner, Romeo Ninov May 10 at 19:13
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
4
Is there a reason you're doing this rather than using a log rotation daemon?
â DopeGhoti
May 9 at 21:33
@DopeGhoti No particular reason, I'll find out.
â c.bruno
May 10 at 9:07
What does âÂÂgoodâ mean in this context? It invites âÂÂyesâ or âÂÂnoâ answers. Does it remove all and only the files you want?
â Jeff Schaller
May 10 at 10:11
add a comment |Â
4
Is there a reason you're doing this rather than using a log rotation daemon?
â DopeGhoti
May 9 at 21:33
@DopeGhoti No particular reason, I'll find out.
â c.bruno
May 10 at 9:07
What does âÂÂgoodâ mean in this context? It invites âÂÂyesâ or âÂÂnoâ answers. Does it remove all and only the files you want?
â Jeff Schaller
May 10 at 10:11
4
4
Is there a reason you're doing this rather than using a log rotation daemon?
â DopeGhoti
May 9 at 21:33
Is there a reason you're doing this rather than using a log rotation daemon?
â DopeGhoti
May 9 at 21:33
@DopeGhoti No particular reason, I'll find out.
â c.bruno
May 10 at 9:07
@DopeGhoti No particular reason, I'll find out.
â c.bruno
May 10 at 9:07
What does âÂÂgoodâ mean in this context? It invites âÂÂyesâ or âÂÂnoâ answers. Does it remove all and only the files you want?
â Jeff Schaller
May 10 at 10:11
What does âÂÂgoodâ mean in this context? It invites âÂÂyesâ or âÂÂnoâ answers. Does it remove all and only the files you want?
â Jeff Schaller
May 10 at 10:11
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
[2-20]+ is not the correct way to test if a number is in the range from 2 to 20. Square brackets in a regular expression just match a single character that matches any of the characters inside it. And - in the character set is used to specify a range of characters (e.g. 2-9 or a-z); the range 2-2 is the same as just 2. So [2-20]+ is equivalen to [20]+, matches any sequence of the characters 2 and 0, such as 2, 20, 02, 2200, etc.
It should be ([2-9]|1[0-9]|20). This matches a single digit from 2 to 9, 1 followed by 0 to 9, or 20.
If you're using GNU find, you can use the -delete operator instead of -exec rm ;.
And there's no need to use 2>&1 if you're not redirecting standard output. By default, both standard output and standard error are sent as mail to the user.
@weekly find /var/log/ ( -iregex '.*.([2-9]|1[0-9]|20)' -o -iname "*.gz" ) -delete
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
[2-20]+ is not the correct way to test if a number is in the range from 2 to 20. Square brackets in a regular expression just match a single character that matches any of the characters inside it. And - in the character set is used to specify a range of characters (e.g. 2-9 or a-z); the range 2-2 is the same as just 2. So [2-20]+ is equivalen to [20]+, matches any sequence of the characters 2 and 0, such as 2, 20, 02, 2200, etc.
It should be ([2-9]|1[0-9]|20). This matches a single digit from 2 to 9, 1 followed by 0 to 9, or 20.
If you're using GNU find, you can use the -delete operator instead of -exec rm ;.
And there's no need to use 2>&1 if you're not redirecting standard output. By default, both standard output and standard error are sent as mail to the user.
@weekly find /var/log/ ( -iregex '.*.([2-9]|1[0-9]|20)' -o -iname "*.gz" ) -delete
add a comment |Â
up vote
2
down vote
accepted
[2-20]+ is not the correct way to test if a number is in the range from 2 to 20. Square brackets in a regular expression just match a single character that matches any of the characters inside it. And - in the character set is used to specify a range of characters (e.g. 2-9 or a-z); the range 2-2 is the same as just 2. So [2-20]+ is equivalen to [20]+, matches any sequence of the characters 2 and 0, such as 2, 20, 02, 2200, etc.
It should be ([2-9]|1[0-9]|20). This matches a single digit from 2 to 9, 1 followed by 0 to 9, or 20.
If you're using GNU find, you can use the -delete operator instead of -exec rm ;.
And there's no need to use 2>&1 if you're not redirecting standard output. By default, both standard output and standard error are sent as mail to the user.
@weekly find /var/log/ ( -iregex '.*.([2-9]|1[0-9]|20)' -o -iname "*.gz" ) -delete
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
[2-20]+ is not the correct way to test if a number is in the range from 2 to 20. Square brackets in a regular expression just match a single character that matches any of the characters inside it. And - in the character set is used to specify a range of characters (e.g. 2-9 or a-z); the range 2-2 is the same as just 2. So [2-20]+ is equivalen to [20]+, matches any sequence of the characters 2 and 0, such as 2, 20, 02, 2200, etc.
It should be ([2-9]|1[0-9]|20). This matches a single digit from 2 to 9, 1 followed by 0 to 9, or 20.
If you're using GNU find, you can use the -delete operator instead of -exec rm ;.
And there's no need to use 2>&1 if you're not redirecting standard output. By default, both standard output and standard error are sent as mail to the user.
@weekly find /var/log/ ( -iregex '.*.([2-9]|1[0-9]|20)' -o -iname "*.gz" ) -delete
[2-20]+ is not the correct way to test if a number is in the range from 2 to 20. Square brackets in a regular expression just match a single character that matches any of the characters inside it. And - in the character set is used to specify a range of characters (e.g. 2-9 or a-z); the range 2-2 is the same as just 2. So [2-20]+ is equivalen to [20]+, matches any sequence of the characters 2 and 0, such as 2, 20, 02, 2200, etc.
It should be ([2-9]|1[0-9]|20). This matches a single digit from 2 to 9, 1 followed by 0 to 9, or 20.
If you're using GNU find, you can use the -delete operator instead of -exec rm ;.
And there's no need to use 2>&1 if you're not redirecting standard output. By default, both standard output and standard error are sent as mail to the user.
@weekly find /var/log/ ( -iregex '.*.([2-9]|1[0-9]|20)' -o -iname "*.gz" ) -delete
answered May 9 at 21:34
Barmar
6,6801122
6,6801122
add a comment |Â
add a comment |Â
4
Is there a reason you're doing this rather than using a log rotation daemon?
â DopeGhoti
May 9 at 21:33
@DopeGhoti No particular reason, I'll find out.
â c.bruno
May 10 at 9:07
What does âÂÂgoodâ mean in this context? It invites âÂÂyesâ or âÂÂnoâ answers. Does it remove all and only the files you want?
â Jeff Schaller
May 10 at 10:11