pertinent parts of python script that creates/writes log files

def kill(fullpath,typ):
    #add check to assure .recycle!!!!
    if any(check for check in requiredChecks if check in fullpath) and typ=='file':
            logFile.write('file -- ' + fullpath + '\n')

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
    logFile = open(logName, 'a') #log file exists, create it and open in append mode
    logFile.write(curDate.isoformat() + '\n')



this script is cron executed daily by root:root. Each day's .log file is a different size, so it is successfully writing.

But I cannot view the file!

administrator@server1: sudo su
root@server1: vi /home/user/backupLogs/recycleBin_2015-06-03.log

vim just opens a blank file and at the bottom says [new file] I double and triple checked that the file does exist.

what is going on here?

  • What is ls -l <filename> saying? – Dominik R Jan 6 '16 at 17:54
  • ls: cannot access recycleBin_2015-06-03.log: No such file or directory – dan Jan 6 '16 at 17:59
  • ls -l | less: -rwxrwxrwx 1 administrator administrator 73279 Jun 1 2015 recycleBin_2015-06-01.log -rw-r--r-- 1 administrator administrator 299 Jun 2 2015 recycleBin_2015-06-02.log -rw-r--r-- 1 administrator administrator 28069 Jun 3 2015 recycleBin_2015-06-03.log – dan Jan 6 '16 at 18:01

You have an extra space in the logName declaration! Add a \ to the filename to open it with vi. And get rid of that extra space in your filename declaration ;)

Edit: that's a backslash and a space

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.