ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I think the problem here is not to find files bigger than a certain size, but to see if a particular file is grown up to that size, right? The find command would be very inefficient if the file resides in a upper level of a directory tree. So, why not simply something like...?
Code:
test $(stat -c \%s /path/to/file) -gt 500000000 && rm /path/to/file
Try it without the part from -exec first, just to make sure it's showing the files you actually want to delete (ie "find /path/to/start/looking/from -size +500M")
Then read "man find".
Edit - you may want to change that to "... rm -f {} ..." depending on the user.
Last edited by billymayday; 11-16-2008 at 06:45 PM.
I think the problem here is not to find files bigger than a certain size, but to see if a particular file is grown up to that size, right? The find command would be very inefficient if the file resides in a upper level of a directory tree. So, why not simply something like...?
Code:
test $(stat -c \%s /path/to/file) -gt 500000000 && rm /path/to/file
I wrote my bit of the code the same time you wrote yours ) so I saw your post after I replied.
Well, if it is a log file you have to stop the process to which the file belongs, before removing. Otherwise the file is not actually removed, that is the inode is preserved (due to the fact the file is in use) and the disk space is not freed.
Well, if it is a log file you have to stop the process to which the file belongs, before removing. Otherwise the file is not actually removed, that is the inode is preserved (due to the fact the file is in use) and the disk space is not freed.
PHP Code:
test $(stat -c \%s /var/log/httpd/error_log) -gt 500000000 && service httpd stop && rm -Rf /var/log/httpd/error_log && service httpd restart
Wouldn't logrotate be good for this too (not every 10 minutes perhaps)?
Your solution also sounds good
logrotate is currently configured to run it's normal rotation for this log as well as for other logs within the same path. I don't think you can make logrotate run just for a single file in that path. Also logrotate runs on cron.daily, and I need this to run on 10 minutes intervals.
I think I'm not able to run the process correctly and need your input on this:
I need the process to delete the error_log file once it is > 500MB.
Just before it deletes it, it needs to STOP httpd, Delete the file, then Restart httpd.
Cron has a very limited environment, for example the PATH is usually /bin:/usr/bin. Therefore it is a good rule to use full path for every command in your script. Most likely the service command, which is usually in /sbin, is not found. Check also the mail of root: all the standard output and the standard error which is not explicitly redirected to a file is sent to the owner of the crontab (use the mail command to find out).
Cron has a very limited environment, for example the PATH is usually /bin:/usr/bin. Therefore it is a good rule to use full path for every command in your script. Most likely the service command, which is usually in /sbin, is not found. Check also the mail of root: all the standard output and the standard error which is not explicitly redirected to a file is sent to the owner of the crontab (use the mail command to find out).
And so,. this is with explicit calls, and still nothing.
I'm confused.
As far as the mail tracing:
less /var/log/exim/mainlog
Quote:
2008-11-29 18:19:02 1L6SX8-0006Dl-1W ** root@server.myserver.com: retry timeout exceeded
2008-11-29 18:19:02 1L6SX8-0006Dl-1W root@server.myserver.com: error ignored
2008-11-29 18:19:02 1L6SX8-0006Dl-1W Completed
2008-11-29 18:19:02 1L6SX7-0006Dj-Uj Completed
2008-11-29 18:20:05 1L6SY5-0006GL-2i <= root@server.myserver.com U=root P=local S=652 T="Cron <root@server> root /usr/bin/cleanApacheEr
rorLogFile.sh" from <root@server.myserver.com> for root
2008-11-29 18:20:05 1L6SY5-0006GL-2i User 0 set for local_delivery transport is on the never_users list
2008-11-29 18:20:05 1L6SY5-0006GL-2i == root@server.myserver.com R=localuser T=local_delivery defer (-29): User 0 set for local_deliver
y transport is on the never_users list
2008-11-29 18:20:05 1L6SY5-0006GL-2i ** root@server.myserver.com: retry timeout exceeded
2008-11-29 18:20:05 1L6SY9-0006HV-Du <= <> R=1L6SY5-0006GL-2i U=mail P=local S=1473 T="Mail delivery failed: returning message to se
nder" from <> for root@server.myserver.com
2008-11-29 18:20:05 1L6SY9-0006HV-Du User 0 set for local_delivery transport is on the never_users list
2008-11-29 18:20:05 1L6SY9-0006HV-Du == root@server.myserver.com R=localuser T=local_delivery defer (-29): User 0 set for local_deliver
y transport is on the never_users list
2008-11-29 18:20:05 1L6SY9-0006HV-Du ** root@server.myserver.com: retry timeout exceeded
2008-11-29 18:20:05 1L6SY9-0006HV-Du root@server.myserver.com: error ignored
2008-11-29 18:20:06 1L6SY9-0006HV-Du Completed
2008-11-29 18:20:06 1L6SY5-0006GL-2i Completed
2008-11-29 18:21:01 1L6SZ3-0006KD-Gp <= root@server.myserver.com U=root P=local S=652 T="Cron <root@server> root /usr/bin/cleanApacheEr
rorLogFile.sh" from <root@server.myserver.com> for root
2008-11-29 18:21:01 1L6SZ3-0006KD-Gp User 0 set for local_delivery transport is on the never_users list
2008-11-29 18:21:01 1L6SZ3-0006KD-Gp == root@server.myserver.com R=localuser T=local_delivery defer (-29): User 0 set for local_deliver
y transport is on the never_users list
2008-11-29 18:21:01 1L6SZ3-0006KD-Gp ** root@server.myserver.com: retry timeout exceeded
2008-11-29 18:21:01 1L6SZ3-0006KQ-KB <= <> R=1L6SZ3-0006KD-Gp U=mail P=local S=1473 T="Mail delivery failed: returning message to se
nder" from <> for root@server.myserver.com
2008-11-29 18:21:01 1L6SZ3-0006KQ-KB User 0 set for local_delivery transport is on the never_users list
2008-11-29 18:21:01 1L6SZ3-0006KQ-KB == root@server.myserver.com R=localuser T=local_delivery defer (-29): User 0 set for local_deliver
y transport is on the never_users list
2008-11-29 18:21:01 1L6SZ3-0006KQ-KB ** root@server.myserver.com: retry timeout exceeded
2008-11-29 18:21:01 1L6SZ3-0006KQ-KB root@server.myserver.com: error ignored
2008-11-29 18:21:01 1L6SZ3-0006KQ-KB Completed
2008-11-29 18:21:01 1L6SZ3-0006KD-Gp Completed
2008-11-29 18:22:02 1L6Sa1-0006MJ-LX <= root@server.myserver.com U=root P=local S=652 T="Cron <root@server> root /usr/bin/cleanApacheEr
rorLogFile.sh" from <root@server.myserver.com> for root
2008-11-29 18:22:02 1L6Sa1-0006MJ-LX User 0 set for local_delivery transport is on the never_users list
2008-11-29 18:22:02 1L6Sa1-0006MJ-LX == root@server.myserver.com R=localuser T=local_delivery defer (-29): User 0 set for local_deliver
y transport is on the never_users list
2008-11-29 18:22:02 1L6Sa1-0006MJ-LX ** root@server.myserver.com: retry timeout exceeded
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.