如何在Cron

时间:2018-03-23 10:26:51

标签: variables unix cron cron-task

我在OS Debian中使用cron文件,使用这样的行:

0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &
0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &
0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &
0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &
0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &
0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &
0 0 * * * php -q /var/www/bbs/public_html/worker/get.php 'domain=someDomain' < /dev/null > /var/www/bbs/public_html/worker/log/someDomain.log &

是否可以在cron文件中创建变量并放入路径:

/var/www/bbs/public_html/worker/

在像这样的代码中使用它:

0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &
0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &
0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &
0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &
0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &
0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &
0 0 * * * php -q $VARIABLE/get.php 'domain=someDomain' < /dev/null > $VARIABLE/log/someDomain.log &

1 个答案:

答案 0 :(得分:0)

我找到了解决方案

TESTDIR=/home/user/test

* * * * * $TESTDIR/script.sh

似乎有效。