I am trying to run the code below as cronjob without any luck...
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:])
The commented sections are for debbuging purposes and whenever the code runs, it shows as the code has finished without errors:
variable start
variable end
tar start
tar end
My crontab settings are:
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
And permissions are the following:
-rwxrwxr-x 1 nagios root 1009 Jan 17 11:00 /app/nagios_install/backup/nagios_backup.py
Can anyone please highlight what I might be doing wrong? Thanks in advance!
17 12 * * * /usr/bin/python /app/nagios_install/backup/nagios_backup.py >> /var/log/nagios_backup.log 2>&1SHELLfor your crontab to be/usr/bin/python, because your command won't make any sense to a python shell (/usr/bin/python /app/nagios_install/backup/nagios_backup.py). If that doesn't suffice, you should drop the output in a log file.