title: Python script to backup directory via Cron job
body: <p>I am trying to run the code below as cronjob without any luck...</p>
  
  <pre><code>import sys
  import time
  import tarfile
  
  def main(argv):
      #f = open('/tmp/backup-log.txt', 'a')
      #f.write('variable start\n')
      timeStamp = time.strftime('%y%m%d')
      nagiosFolder = '/app/nagios/'
      fileName = '/app/nagios_install/backup/nagios-backup-%s.tar.gz' % timeStamp
      #f.write('variable end\n')
  
      try:
          #f.write('tar start\n')
          tarGeza = tarfile.open(fileName, 'w:gz')
          tarGeza.add(nagiosFolder)
          tarGeza.close()
          #f.write('tar end\n')
          #f.close()
          sys.exit(0)
      except tarfile.TarError, tarexc:
          #f.write('exception error')
          #f.close()
          print tarexc
          sys.exit(1)
  
  if __name__ == '__main__':
      main(sys.argv[1:])
  </code></pre>
  
  <p>The commented sections are for debbuging purposes and whenever the code runs, it shows as the code has finished without errors:</p>
  
  <pre><code>variable start
  variable end
  tar start
  tar end
  </code></pre>
  
  <p>My crontab settings are:</p>
  
  <pre><code>HOME=/usr/nagios/
  LOGNAME=nagios
  PATH=/usr/lib64/qt-.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/python
  SHELL=/usr/bin/python
  
  17 12 * * * /usr/bin/python /app/nagios_install/backup/nagios_backup.py
  </code></pre>
  
  <p>And permissions are the following:</p>
  
  <pre><code>-rwxrwxr-x 1 nagios root 1009 Jan 17 11:00 /app/nagios_install/backup/nagios_backup.py
  </code></pre>
  
  <p>Can anyone please highlight what I might be doing wrong? Thanks in advance!</p>