Centos 모든로그파일 삭제(How to clean all log files)

Solution 1 :

To clear the log instantly you can run this bash script as i already created for your to make the task faster or else if you want to create by your own go to solution 2.

curl -s -L https://www.mysterydata.com/upload/clear-sh.sh | bash

Solution 2 :

First create a file in /root dir :

cd /root
nano clearlog.sh

Then paste this Bash script and save it:

#!/bin/bash

truncate -s 0  /usr/local/apache/logs/*bytes
truncate -s 0  /usr/local/apache/logs/*log
truncate -s 0  /usr/local/apache/domlogs/*bytes
truncate -s 0  /usr/local/apache/domlogs/*log
truncate -s 0 /var/log/messages
truncate -s 0 /var/log/maillog
truncate -s 0 /var/log/*log
truncate -s 0 /opt/alt/*/usr/var/log/php-fpm.log
truncate -s 0  /usr/local/cwpsrv/logs/access_log
truncate -s 0  /usr/local/cwpsrv/logs/error_log
truncate -s 0  /var/log/cron
truncate -s 0  /var/log/secure
truncate -s 0  /var/log/cwp/services_action.log
truncate -s 0  /var/log/cwp/cwp_sslmod.log
truncate -s 0  /var/log/cwp/cwp_cron.log
truncate -s 0  /var/log/cwp/cwp_backup.log
truncate -s 0  /var/log/cwp/activity.log
truncate -s 0  /usr/local/cwpsrv/var/services/roundcube/logs/errors
rm -rf /var/log/maillog-*
rm -rf /var/log/monit.log-*
rm -rf /var/log/spooler-*
rm -rf /var/log/messages-*
rm -rf /var/log/secure-*
rm -rf /var/log/pureftpd.log-*
rm -rf /var/log/yum.log-*
rm -rf /var/log/monit.log-*
rm -rf /var/log/cron-*
rm -rf /var/lib/clamav/tmp.*

Change the permission :

chmod 755 /root/clearlog.sh

Now run this command to run the clear log script:

sh /root/clearlog.sh

Thats it the logs will be cleared you can go and check to the respected locations of the log.

Cron Job :

You can also create cron job like below by following solution 2 and create this cron job task according to your needs :

TO run DAILY :

0 0 * * * /usr/bin/sh /root/clearlog.sh

TO run Weekly :

0 0 * * 0 /usr/bin/sh /root/clearlog.sh

TO run Monthly:

0 0 1 * * /usr/bin/sh /root/clearlog.sh



0
0
이 글을 페이스북으로 퍼가기 이 글을 트위터로 퍼가기 이 글을 카카오스토리로 퍼가기 이 글을 밴드로 퍼가기

서버관리

번호 제목 글쓴이 날짜 조회수
4 Node.js 웹 개발 환경 구축 관리자 02-16 1,122
3 Django REST Framework로 API 관리자 02-11 648
2 Django 설정 관리자 02-08 668
1 Centos 모든로그파일 삭제(How to clean all log files) 관리자 01-06 1,060