Crontab运行问题 [英] Crontab running issue

查看:132
本文介绍了Crontab运行问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有500个php文件,我想制作一个crontab来自动运行它们(他们存储XML数据在我的数据库)我的问题是:



crontab为每个php文件它工作正常。命令如下:

  * * * * * php /home/username/public_html/codes/php0.php 

但是当我想运行一个shell脚本,包括我所有的php文件,如下:

  * * * * * bash /home/username/public_html/codes/php.sh 

它不会运行。



php.sh:

 #!/ bin / sh 

php php0.php
echo php0
php php1.php
echo php1
php php2.php
echo php2



是否可以用bash脚本包装php文件?

解决方案

你可能没有在你认为你的目录中运行。



因此请用#!/ bin / sh临时替换#!/ bin / sh -vx
并添加

  pwd 


然后,在脚本的开头(即第二行)输入



可能添加

  cd / home / username / public_html / codes 

或者可以定义一个变量并使用它:

  mycodedir = / home / username / public_html / codes 
php $ mycodedir / php0.php
echo php0


$ b b

等...



我建议您阅读高级bash脚本指南(即使它有弱点)。


I have 500 php files i want to make a crontab to run them automatically (they store XML data in my database) my problem is :

when I make a crontab for each php file it works fine. the command like this:

* * * * * php /home/username/public_html/codes/php0.php

But when I want to run a shell script including all my php files like this :

* * * * * bash /home/username/public_html/codes/php.sh

it does not run.

php.sh:

#!/bin/sh

php php0.php
echo php0
php php1.php
echo php1
php php2.php
echo php2
.
.
.

Is it possible to wrap php files with bash script? and if yes why does not work am I miss something?

解决方案

You are probably not running in the directory you believe you are.

So replace temporarily #!/bin/sh with #!/bin/sh -vx and add a

  pwd

at the beginning of your script (that is, the 2nd line)

Then perhaps add a

 cd /home/username/public_html/codes

or maybe define a variable and use it:

 mycodedir=/home/username/public_html/codes
 php $mycodedir/php0.php
 echo php0

etc...

I suggest to read the advanced bash scripting guide (even if it does have weaknesses).

这篇关于Crontab运行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆