Link to home
Start Free TrialLog in
Avatar of badwolfff
badwolfffFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I use a cronjob to truncate all logs on my Centos 7 server to 1 gig max size?

I am running a VPS with centos 7 and have several websites sites hosted on it (wordpress, magento, joomla, opencart, corephp). I am looking for a way (cronjob if possible) that can truncate the various error.log and other log files of these sites to a max size of 1 gb each. I am imagining a script that can search for .log files on the server and truncate them at a fixed interval, if it is possible to create such a cronjob (using logrotate?). If not I don't mind setting one cronjob per error.log or whatever.log file if someone here could help me create the cronjob query that can do it.

thanks in advance
Avatar of Zephyr ICT
Zephyr ICT
Flag of Belgium image

Maybe I'm missing the intended goal, but if you use logrotate you can let the logs rotate on the size you want, with the "size" parameter.

From the MAN:
size
Log files are rotated only if they grow bigger then size bytes. If size is followed by k, the size is assumed to be in kilobytes. If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100Gare all valid.
Avatar of badwolfff

ASKER

Yes thanks, I had heaed about logrotate but have absolutely no idea about using it.
There are many log files on my server and they are getting bulkier by the day.

How do I run or program or activate this "logrotate"?
Could you help me with the steps as I don't even know where to begin and I certainly don't want to do anything that might bugger up the whole server!
ASKER CERTIFIED SOLUTION
Avatar of Zephyr ICT
Zephyr ICT
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial