[英]PHP Exec Cron Job returns unexpected EOF
I'm attempting to run a php script during a cron job to dump my MySQL database to a folder for a backup. 我正在尝试在cron作业期间运行php脚本,以将我的MySQL数据库转储到用于备份的文件夹中。
$DBHost = 'localhost';
$DBName = 'mydatabase';
$DBUser = 'myuser';
$DBPassword = 'mypassword';
$PATH = "/home/mysite/Backups/";
$FILE_NAME = "backup-" . date( "Y-m-d_H:i:s" ) . ".sql.gz";
exec( '/usr/local/bin/mysqldump -u ' . $DBName . ' -p' . $DBPassword . ' ' . $DBName . ' | gzip --best > ' . $PATH . $FILE_NAME );
But I keep getting the error: 但我不断收到错误:
sh: -c: line 0: unexpected EOF while looking for matching `)'
sh:-c:第0行:寻找匹配的`)'时出现意外的EOF
sh: -c: line 1: syntax error: unexpected end of file
sh:-c:第1行:语法错误:文件意外结束
I have checked all the )
and can't find any non-matching. 我已经检查了所有
)
,但找不到任何不匹配的内容。 If I comment out the exec
command then I do not get the error. 如果我注释掉
exec
命令,那么我不会收到错误。
Any one see what I am doing wrong? 有人看到我在做什么错吗?
Why don't write whole code in sh? 为什么不用sh编写整个代码?
#!/bin/bash
dbname="database"
dbuser="user"
dbpass="password"
path="/home/backup"
now=$(date + "%Y-%m-%d")
/usr/bin/mysqldump -u $dbuser -p$dbpass $dbname | gzip > $path/backup_$now.sql.gz
save it as eg backup.sh, 保存为例如backup.sh,
and then use crontab -e to add new cron job (eg 2:15 daily) 然后使用crontab -e添加新的cron作业(例如每天2:15)
15 2 * * * /home/backup/backup.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.