My shell script run perfectly by putty command but when I put it in crontab it doesnot work

I have two shell script named: backup_inventory_sourcecode.sh and backup_bash.sh. I run these two .sh file using as putty as follows:

sh /var/www/html/backup_inventory_sourcecode.sh
sh /var/www/html/backup_bash.sh 

it runs successfully and created a zip file and sql file file respectively. The content of backup_inventory_sourcecode.sh is:

#!/bin/bash

NOW=$(date +"%m_%d_%Y")


sudo zip -r /inventory_sourcecode_backup/inventory_backup_${NOW}.zip /var/www/html/inventory -x ".git"

sync
/var/www/html/ftpupload.sh /inventory_sourcecode_backup/inventory_backup_${NOW}.zip

and content of backup_bash.sh is:

#!/bin/bash
NOW=$(date +"%m_%d_%Y_%H_%M_%S")
NOW=${NOW}_Inventory
mysqldump -u root -pAplrootuser  db_apl_inventory >/db_backup/${NOW}.sql

#sleep 30
/var/www/html/ftpupload.sh /db_backup/${NOW}.sql

Now I put the two lines in crontab:

*/1 * * * * sh /var/www/html/backup_inventory_sourcecode.sh
*/1 * * * * sh /var/www/html/backup_bash.sh

these should create .zip and .sql file respectively. but it produce only .sql file. It proves only */1 * * * * sh /var/www/html/backup_bash.sh works but not */1 * * * * sh /var/www/html/backup_inventory_sourcecode.sh. What is the problem.

0
задан 20 December 2017 в 13:36
1 ответ

Путь Cron по умолчанию зависит от реализации, поэтому проверьте свою страницу руководства.

Вы можете определить свою собственную переменную PATH в вашем файле crontab.

PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
*/1 * * * * sh /var/www/html/backup_inventory_sourcecode.sh
*/1 * * * * sh /var/www/html/backup_bash.sh
0
ответ дан 5 December 2019 в 07:00

Теги

Похожие вопросы