创build/写入日志文件的python脚本的相关部分
def kill(fullpath,typ): #add check to assure .recycle!!!! if any(check for check in requiredChecks if check in fullpath) and typ=='file': os.remove(fullpath) logFile.write('file -- ' + fullpath + '\n') return curDate = datetime.datetime.now() logName = '/home/user/backupLogs/recycleBin_'+curDate.strftime('%Y-%m-%d')+'.log ' logFile = '' if not os.path.exists(logName): logFile = open(logName,'w') #log file doesn't exist, create it and open in write mode else: logFile = open(logName, 'a') #log file exists, create it and open in append mode logFile.write(curDate.isoformat() + '\n') kill("/some/file/path.foo","file") logFile.close()
这个脚本每天都以root身份执行。 每天的.log文件是不同的大小,所以它是成功的写作。
但我无法查看文件!
administrator@server1: sudo su root@server1: vi /home/user/backupLogs/recycleBin_2015-06-03.log
vim只是打开一个空白文件,在底部说[新文件]我双重和三重检查,该文件确实存在。
这里发生了什么?
在logName声明中有一个额外的空间! 添加\到文件名用vi打开它。 并删除您的文件名声明中的额外空间;)
编辑:这是一个反斜杠和一个空格