crontab

django-crontab的使用

牧云@^-^@ 提交于 2019-12-02 05:15:35
django-crontab实现服务端的定时任务 安装 pip install django-crontab 在Django项目中使用 settings.py INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_crontab' ) # 在settings.py中可以这么使用: CRONJOBS=( # 每一分钟执行一次你的定时函数 ('*/ * * * *', 'appname.cron.test'), # 定时函数输出的内容到指定文件(如果该路径或文件不存在将会自动创建) ('0 0 1 * *', 'app名.定时函数所在文件名.定时函数名', '>输出文件路径和名称'), # 在12点10分执行命令 ('10 12 * * *', 'django.core.management.call_command', ['要执行的命令']), ) 在app中(与views.py同级)新建cron.py文件(文件名不限定) def test(): print(

cron job to remove old data from postgres on debian

夙愿已清 提交于 2019-12-02 05:00:29
I need to create a cron that runs every night and remove some of the data (older ones) from my database. I am running postgres on debian. How do I do that? My server is tomcat6. Does anyone have a step by step instruction including script to do that? in most cases, I prefer a shell script with an here-document. (shell-variables expand nicely in here-documents): #!/bin/sh PSQL=/local/postgres/bin/psql SOME_VALUE=123 $PSQL my_database <<THE_END DELETE FROM my_table WHERE my_column <= $SOME_VALUE ; THE_END Several good ways. You may want to do more than just one DELETE . Run ANALYZE tbl ? Handle

Adding dynamic cron jobs to GAE

无人久伴 提交于 2019-12-02 04:47:56
问题 In GAE we can add cron job manually by editing the cron.xml file <?xml version="1.0" encoding="UTF-8"?> <cronentries> <cron> <url>/cron/addCount/1</url> <description>Add count + 1 every 1 minutes</description> <schedule>every 1 minutes</schedule> </cron> </cronentries> Is there any way that I can make a user interface and create/update/delete as many cron jobs on the fly.That means after I deploy to GAE , I should be able to update the cron.xml ? Or is there a work around so that I can create

unexpected EOF cronjob error

左心房为你撑大大i 提交于 2019-12-02 02:22:20
I have the following cronjob: 2 15 * * * mysqldump -u user -ppass dbname | gzip -9 -c > /var/www/backup/dump-$(date +%Y-%m-%d).sql.gz but it produces following error: /bin/sh: -c: line 0: unexpected EOF while looking for matching ')' /bin/sh: -c: line 1: syntax error: unexpected end of file I tried ommiting -c but no luck. I have one more line in my crontab but I don't think it's related: 0 0 * * * find /var/www/backup/* -mtime +15 -exec rm {} \; Thanks The % character should be escaped in cron . So, 2 15 * * * mysqldump -u user -ppass dbname | gzip -9 -c > /var/www/backup/dump-$(date +\%Y-\%m

Adding dynamic cron jobs to GAE

泪湿孤枕 提交于 2019-12-02 01:52:17
In GAE we can add cron job manually by editing the cron.xml file <?xml version="1.0" encoding="UTF-8"?> <cronentries> <cron> <url>/cron/addCount/1</url> <description>Add count + 1 every 1 minutes</description> <schedule>every 1 minutes</schedule> </cron> </cronentries> Is there any way that I can make a user interface and create/update/delete as many cron jobs on the fly.That means after I deploy to GAE , I should be able to update the cron.xml ? Or is there a work around so that I can create cron jobs on the fly ? No this is not possible. You should just save this schedule data to datastore,

Running a PHP script with crontab

走远了吗. 提交于 2019-12-02 01:30:45
问题 I understand SO is for questions but no matter how many tutorials I have looked up, I cannot get my crontab to work and I am building an website that will rely on crontab to reset a particular setting in my database every night. Here is my crontab file: # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you

How to run an R script in crontab

北慕城南 提交于 2019-12-02 00:42:45
Using crontab -e I've tried: * * * * * Rscript /home/.../file.r * * * * * /usr/lib/R/bin/Rscript /home/.../file.r * * * * * /usr/bin/Rscript /home/.../file.r * * * * * /home/.../foo.sh where foo.sh contains: sudo R CMD BATCH file.r Just running $ ./foo.sh works. $ R CMD BATCH file.r works. Nothing I've tried in crontab works. Any ideas? You'll need to have the full path in your foo.sh: sudo R CMD BATCH /home/.../file.r I should also add that the first version worked for me, although I set it to a specific time rather than * * * * * For what it is worth here is CRANberries entry which has

why my cron job executing multiple times?

霸气de小男生 提交于 2019-12-02 00:25:42
问题 I have set up a cron job that need to be executed once a day but it is getting executed multiple times.I have set up it as I mentioned below: 5 8 * * * /sh_file_path Can anyone please tell me why is this happening and what should I do to resolve this problem. 回答1: Without more knowledge about your particular setup/system, and the fact that all jobs get executed multiple times, I can only surmise that you have multiple cron daemons running on your system. Do a full process list and grep for

Running a PHP script with crontab

我怕爱的太早我们不能终老 提交于 2019-12-01 23:56:09
I understand SO is for questions but no matter how many tutorials I have looked up, I cannot get my crontab to work and I am building an website that will rely on crontab to reset a particular setting in my database every night. Here is my crontab file: # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of

centos crontab定时任务用法

徘徊边缘 提交于 2019-12-01 23:18:06
一、安装crond服务 yum -y update yum -y install cronie yum-cron 二、crontab任务语法 crontab任务配置基本格式: * *  *  *  *  command 第1列表示分钟0~59 每分钟用 * 或者 */1 表示 第2列表示小时0~23(0表示0点) 第3列表示日期1~31 第4列表示月份1~12 第5列标识号星期0~6(0,7都可表示星期天) 第6列要运行的命令或执行shell脚本 综合起来就是: 分钟(0-59) 小时(0-23) 日期(1-31) 月份(1-12) 星期(0-6,0代表星期天)  命令 从上面可以看出,crontab最小的时间单位: 1分钟。如果要每30秒执行一次脚本,要么写个小脚本,要么在crontab增加延迟。 例子:crontab中增加延迟30秒来实现 a、crontab -e,添加如下内容: */1 * * * * sh && echo "dd" >> /logs/cron-cc.log */1 * * * * sleep 30 && echo "cc" >> /logs/cron-cc.log b、重启crond systemctl reload crond systemctl restart crond c、查看当前用户定时任务 crontab -l d、通过日志查看是否生效 tail