通过crontab启动时,PHP脚本失败(“目录”
我有一个PHP脚本创建MySQL转储,从浏览器启动时可以很好地工作。它通过exec()函数调用mysqldump。
我将此PHP脚本安排为 root (在Ubuntu VPS上)。以下错误消息失败:
sh:1:无法创建./backups/db_20220522.sql:目录nothxistent
i set_include_path('/var/www/mysite.com/');在我的PHP脚本的开头。脚本和“备份”目录在其中。
我想念什么?
非常感谢您的帮助
I have a PHP script creating a MySQL dump, working perfectly when launched from the browser. It calls mysqldump through the exec() function.
I scheduled this PHP script as root in the crontab (on an Ubuntu VPS). It fails with the following error message :
sh: 1: cannot create ./backups/db_20220522.sql: Directory nonexistent
I have set_include_path('/var/www/mysite.com/'); at the beginning of my PHP script. The script and the "backups" directory are in there.
What am I missing ?
Thanks a lot for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在脚本中指定备份目录的完整路径。
Cron从其他目录运行。
例如
You need the specify the full path to your backup directory in your script .
Cron runs from a different directory.
eg