简体   繁体   English

Cron作业的工作目录

[英]Working Directory for a Cron Job

I am testing an application in MAMP and would like to add a cron job, or as I am on a mac the job through is run through launchctl . 我正在MAMP中测试应用程序,并想添加一个cron作业,或者像在Mac上一样,该作业通过launchctl运行。 My cron is a php file that runs a database query. 我的cron是运行数据库查询的php文件。 Naturally the php file and mysql db are in separate directories. 当然,php文件和mysql db位于单独的目录中。 Where should I change my working directory to such that the cron will query the database? 我应该在哪里将工作目录更改为cron将查询数据库? FYI, I have a standard installation /Applications/MAMP/... 仅供参考,我有一个标准安装/Applications/MAMP/...

Many thanks. 非常感谢。

My mistake above was that I was trying to point to the database's directory, when the php file had already handled that for me. 我上面的错误是我试图指向数据库的目录,而php文件已经为我处理了。 Running the program was as simple as running the following code: 运行该程序就像运行以下代码一样简单:

php -q /path/to/my/doc.php

I found it was easiest to manage launchtl through a $5-$10 program called lingon . 我发现这是最容易管理launchtl通过称为$ 5 - $ 10个节目lingon Highly recommended if you are considering managing multiple crons at a time. 如果您正在考虑一次管理多个分支,则强烈建议。 Otherwise, if you want to stick to the command line, this is a good tutorial. 否则,如果您想坚持使用命令行, 是一个很好的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM