crontab

How to set a crontab using php?

那年仲夏 提交于 2019-12-06 11:36:10
问题 i need to set a crontab from a php script. i know that it can be set by system("echo '* * * * * echo \"Hello world\"' >> cron.crontab"); system("crontab cron.crontab"); //cron.crontab is the file name of the crontab "cron.crontab" file is created in root directory, but crontab is not working as expected! when i try the following command, it says that no crontab is set! crontab -l i think i am missing something. i am using yii framework. is there an extension to handle cron in yii framework?

How do I get colored output to a file from a bash script running in crontab?

不问归期 提交于 2019-12-06 10:29:35
When I run a bash script manually, the output appends my log file in the color specified using tput. When I run the bash script as a cronjob, the output loses the color. Thanks. Your cron environment almost certainly is just not specifying a terminal type that supports colors and so tput is not returning anything. Compare: $ echo $TERM xterm-256color $ printf %q\\n "$(tput setaf 5)" $'\E[35m' $ printf %q\\n "$(TERM=dumb tput setaf 5)" '' I put TERM=xterm export TERM in the bash_profile file and the colors are working. 来源: https://stackoverflow.com/questions/25512588/how-do-i-get-colored-output

crontab执行身份的小坑

徘徊边缘 提交于 2019-12-06 09:11:49
有个ubuntu服务器,跑着apache, PHP7, Laravel,supervisor。 apache和supervisor都是www-data用户。 平时管理员ssh登上去用的都是devuser用户。 今天发现Laravel日志异常了,连着几天都是只有短短一行日志记录。 新的日志都写不进去。chown 改成 www-data 后日志还是写不进去,见了鬼了。 后来尝试重启 apache, supervisor, PHP7 ,然后重命名掉今天的日志文件,发现新日志终于有了。是正常的 www-data 用户的文件。 怀疑为什么会有 devuser 的日志文件产生: 有人用 devuser 身份 SSH 登进来搞事情。 有什么软件是以 devuser 身份执行了。 我们检查了 apache, supervisor, PHP配置文件, 都是 www-data。百思不得其解。 最后排查到定时任务,才想起来我们使用了 crontab 来重复触发 artisan schedule:run 来执行定时任务。 由于我们使用了 devuser 来配置的 crontab -e,所以执行身份肯定是 devuser。 最后我们将 schedule:run 命令写入了 /etc/crontab 里面,指明用 www-data 执行。 天下太平了。 来源: oschina 链接: https://my

Yii and cron jobs

倾然丶 夕夏残阳落幕 提交于 2019-12-06 08:44:37
问题 I have created a Yii command that needs to be run every month. If I go to my protected folder and run the command manually: protected/yiic ganadores It works fine. I have tried to add the following command line to etc/cron.hourly and etc/crontab with no success: /usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores (etc/cron.hourly/ganadores) 0 0 1 * * root /usr/bin/php5 /var/www/path/to/project/protected/yiic ganadores (etc/crontab) If I run the file ganadores inside etc/cron

linux命令 - crontab

[亡魂溺海] 提交于 2019-12-06 06:59:17
第一个 进入 crontab 会选择编译器 在开发中一般写成脚本形式运行 2>&1 表示把错误也输入到 run.log 中去 图片上面的两个2>1 是不一样的 对应的不同命令 /bin/sh 表现下面命令用 /bin/sh 执行 类似于python 代码写的 /bin/sh/python3 cd `dirname $0` 不是引号是反引号 表示进入当前目录 || exit 1 表示中不到目录就退出    https://tool.lu/crontab/ 间隔实际测试工具 来源: https://www.cnblogs.com/wang102030/p/11967509.html

crontab命令

本秂侑毒 提交于 2019-12-06 06:55:26
crontab命令 被用来提交和管理用户的需要周期性执行的任务,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程,crond进程每分钟会定期检查是否有要执行的任务,如果有要执行的任务,则自动执行该任务。 语法: crontab [ -u user ] file 或 crontab [ -u user ] { -l | -r | -e } 说明: crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类似使用者的时程表。 -u user 是指设定指定 user 的时程表,这个前提是你必须要有其权限(比如说是 root)才能够指定他人的时程表。如果不使用 -u user 的话,就是表示设定自己的时程表。 参数: -e : 执行文字编辑器来设定时程表,内定的文字编辑器是 VI,如果你想用别的文字编辑器,则请先设定 VISUAL 环境变数来指定使用那个文字编辑器(比如说 setenv VISUAL joe) -r : 删除目前的时程表 -l : 列出目前的时程表 -u<用户名称>:指定要设定计时器的用户名称。 crontab文件的含义:用户所建立的crontab文件中,每一行都代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,格式如下:

Cannot import mysql-python in crontab Mac OS

 ̄綄美尐妖づ 提交于 2019-12-06 06:29:35
I wrote a script which runs ok, but when I run it from crontab I get an import error. Traceback (most recent call last): File "/Users/.../Desktop/test.py", line 3, in <module> import MySQLdb as mysql File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module> File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module> File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__ ImportError: dlopen(/Users/.../.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced

Running python scripts consecutively in Crontab

人走茶凉 提交于 2019-12-06 05:26:25
I am attempting to run my compilation of scripts one after another every minute. Example: Assuming each script takes 2 seconds to finish: start script 1 at 1:00, script 2 at 1:02, script 3 at 1:04, etc... I assume it should look something like this */1 * * * * python script1.py && python script2.py && python script3.py * * * * * python /path/to/script1.py ; python /path/to/script2.py ; python /path/to/script3.py Use && if you want to run the second script only if the first script is successful (exit code is 0) Use ; if you want to always run the second script irrespective of first script's

Linux中crontab定时任务

匆匆过客 提交于 2019-12-06 05:01:10
crontab安装(centOS) yum -y install vixie-cron crontab语法(计划任务) crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e (edit user's crontab) 编辑 -l (list user's crontab) 显示所有任务 -r (delete user's crontab) 删除 -i (prompt before deleting user's crontab) -s (selinux context) crontab格式 使用crontab -e 添加要执行的命令。 添加的命令必须以如下格式: * * * * * /command path 前五个字段可以取整数值,指定何时开始工作,第六个域是字符串,即命令字段,其中包括了crontab调度执行的命令。 各个字段之间用spaces和tabs分割。 前5个字段分别表示: 分钟:0-59 小时:1-23 日期:1-31 月份:1-12 星期:0-6(0表示周日) 一些特殊符号: *: 表示任何时刻 ,: 表示分割 -:表示一个段,如第二端里: 1-5,就表示1到5点 /n : 表示每个n的单位执行一次,如第二段里,*

Hourly cronjob on Windows

时光毁灭记忆、已成空白 提交于 2019-12-06 04:53:59
I just setup cron on my windows dev system in order to perform an hourly run of a script. I tried to edit crontab in order to run my script hourly, sadly with no success. Could anyone pls. drop me the crontab line which will execute script.xy every hour? If you're using Windows, why not use the built-in Scheduled Tasks (Accessories-System Tools)? It may not show up immediately in the Wizard, but it is possible to set up tasks to be run hourly. Just add a daily task and then tick the "Open Advanced Properties" checkbox. Then go to the Schedule tab and again click "Advanced". I figured it out: 0