0

im having the problem that a bash script is not running from cron. When i instead run it as root from the cli it works well. As you can see i write to a txt file when the script has finished. This is also done when the script runs from cron, only the Oracle dmp is not saved (and obviously not zipped). The job is done extremely quick, so i guess it does not do the oracle export...

Thank you for you help!

backup.sh

#!/bin/bash
#makes an Oracle  backup and zips the created file
TIME=`date +%F_%H:%M:%S`
FILENAME=Backup-$TIME

exp userid=user/password file=/home/user/DatabaseBackup/$FILENAME.dmp
zip /home/user/DatabaseBackup/$FILENAME.zip /home/user/DatabaseBackup/$FILENAME$
find /home/user/DatabaseBackup/ -mtime +0 -type f -delete

echo "Backup completed:" `date +%F_%H:%M:%S` >> /home/user/scripts/logBackup.txt
#END

crontab -e 26 * * * * /home/user/scripts/backup.sh

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
helmut1978
  • 417
  • 6
  • 17
  • 1
    Add full path to executables (date, exp, zip, find). – Cyrus Apr 01 '17 at 09:56
  • 1
    You should capture the output of the cron job (stdin and stderr) before requesting assistance, as any error message found in this output is likely to make it easier for you to find the cause, or for anyone else to help you. Jobs executing in `cron` can have a different environment, and it is likely your problem comes from a difference in `PATH` or some other variable any of the programs you use relies on. – Fred Apr 01 '17 at 11:51
  • Fred1 Your are right, it is best to check the output of the programs called! Ill do and look whats going wrong – helmut1978 Apr 01 '17 at 13:16

1 Answers1

0

Ok, what i did is:

I added

>> /home/user/cron.txt 2>&1

this to my cronjob declaration, wiht this i have now the output of the cornjob.

With this it was easy to find out that some evironmet variables for oracle were missing...

Thanks for any help provided!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
helmut1978
  • 417
  • 6
  • 17