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:


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

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

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

and content of backup_bash.sh is:

NOW=$(date +"%m_%d_%Y_%H_%M_%S")
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.

  • scripts from cron run under a different user and with different environment variables. You should make sure that each stage of your script runs fine and put errors into a log file. Then you'll be able to pinpoint the problem Commented Dec 20, 2017 at 11:41
  • probably the zip or sudo command is not found. Try to use them with absolute path. Sudo imho is not needed if the cron is run as root
    – mbieren
    Commented Dec 20, 2017 at 12:18

1 Answer 1


Cron's default path is implementation-dependent, so check your man page.

You can define your own PATH variable in your crontab file.

*/1 * * * * sh /var/www/html/backup_inventory_sourcecode.sh
*/1 * * * * sh /var/www/html/backup_bash.sh
  • but when I access the remote server I can see the path starting at /var Commented Dec 20, 2017 at 11:59
  • The PATH variable in your session and they crontab session is most likely different.
    – eKKiM
    Commented Dec 20, 2017 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .