今天,由于oracle trace目录下面的文件太多了,就用python写了个脚本,将跟踪文件只保留5天,5天以外的文件全部删除。
具体实现脚本DeleteFile.py,脚本具体内容如下:
Linux下调用python
再通过crontab来定时调用上面的python 脚本
具体实现脚本DeleteFile.py,脚本具体内容如下:
__author__ = 'Administrator' import os; import sys; import time; class DeleteLog: def __init__(self,filename,days): self.filename=filename; self.days=days; def delete(self): if os.path.exists(self.filename)==False: print(self.filename+ ' is not exists!!') elif os.path.isfile(self.filename): print(self.filename); elif os.path.isdir(self.filename): print(self.filename + ' is a path!'); for i in [os.sep.join([self.filename,v]) for v in os.listdir(self.filename)]: if self.compare_file_time(i) and (os.path.isfile(i)): os.remove(i); print(i+' is removed!'); def compare_file_time(self,file): time_of_last_mod=os.path.getatime(file); days_between=(time.time()-time_of_last_mod)/(24*60*60); if days_between>self.days: return True; return False; if __name__=='__main__': path='/u01/app/diag/rdbms/orcl/orcl/trace'; obj=DeleteLog(path,5); obj.delete();
Linux下调用python
[root@LINUX142 scripts]# python
DeleteFile.py
再通过crontab来定时调用上面的python 脚本
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30150152/viewspace-1475208/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30150152/viewspace-1475208/