Search code examples
phpcroncron-task

mysqldump-cronjob creates a new php-file, each time it is called


I have a cronjob that looks like this:

mysqldump -u XXX -pXXX XXX | gzip -9 > /data/web/xyz123/html/temporary/backup-$(date +%Y%m%d).sql.gz

every time the cronjob is called, the .sql.gz-file is generated. All is good. But I recognized, that the cronjob also generates a file in the root Directory called crontab.php.1, crontab.php.2, crontab.php.3... every time the cronjob is called.

The relevant code in the crontab.php is:

  if(!empty($data['set_backup_email'])){
   if(sendmail($data['set_backup_email'], 'Backup '.date('Y-m-d'), 'Im Anhang befindet sich das Backup vom '.$day[date('N')].', '.date('d.m.Y').'.', $file, '[email protected]')){
    protocol(61);
    unlink($file);
   }else{
    protocol(62);
    send2admin('Das Datenbank-Backup konnte nicht zugestellt werden');
   }
  }

Solution

  • you are calling php file in the wrong way.

    run this command on your linux server

    which php
    

    it will give you the path to your php, it will be something like /to/path/php

    Add the line in your cron tab as:

    * * * * * /to/path/php /filepath/crontab.php

    Use * as per your requirements.

    The php file should be on the server.