crontab

定时任务crond、crontab

倾然丶 夕夏残阳落幕 提交于 2019-11-27 12:38:30
crontab命令是用来设置定时任务规则的配置命令,配置文件/etc/crontab 与/var/spool/cron/目录下当前用户名的文件。   -l 显示当前定时任务   -e 编辑定时任务 对于root用户: crontab -l 等同于 cat /var/spool/cron/root crontab -e 等同于 vim /var/spool/cron/root crond.service服务管理 要想配置定时任务,首先启动crond服务。 systemctl start crond.service systemctl stop crond.service systemctl status crond.service 开启自启动: systemctl disable crond.service systemctl enable crond.service /etc/crontab 配置问价介绍: [root@55test /etc]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute

Need to set up rvm environment prior to every cron job

微笑、不失礼 提交于 2019-11-27 11:48:51
问题 I installed and configured RVM roughly following the pattern outlined in the first part of this set of instructions: http://blog.ninjahideout.com/posts/a-guide-to-a-nginx-passenger-and-rvm-server Basically, this means there is no pre-build system ruby (all ruby installs are RVM-managed) and RVM is installed system-wide instead of attached to a particular user (files at /usr/local/rvm ) so all users in the rvm group can access the same rubies with the same installed gems. One issue with

Django custom command and cron

霸气de小男生 提交于 2019-11-27 11:36:50
I want my custom made Django command to be executed every minute. However it seems like python /path/to/project/myapp/manage.py mycommand doesn't seem to work while at the directory python manage.py mycommand works perfectly. How can I achieve this ? I use /etc/crontab with: ****** root python /path/to/project/myapp/manage.py mycommand I think the problem is that cron is going to run your scripts in a "bare" environment, so your DJANGO_SETTINGS_MODULE is likely undefined. You may want to wrap this up in a shell script that first defines DJANGO_SETTINGS_MODULE Something like this: #!/bin/bash

Cron Job - How to send an output file to an email

给你一囗甜甜゛ 提交于 2019-11-27 11:35:27
问题 I have this line in crontab: * * * * * /var/www/dir/sh/mysql_dumb.sh | mail -s "mysql_dump" example@mail.com (every minute only a sample) So, all works fine, but the email is empty. UPDATE: The output from mysql_dumb.sh is a *.sql file and they save the file in a directory. How can I send a copy (*.sql file) from this output -> mysql_dumb.sh to my email? mysql_dumb.sh: #!/bin/bash PATH=/usr/bin:/bin SHELL=/bin/bash /usr/bin/mysqldump -u USER -pPASS DATABASE > /var/www/dir/backup/backup_DB_

Crontab not running my python script

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 11:14:44
My python script is not running under my crontab. I have placed this in the python script at the top: #!/usr/bin/python I have tried doing this: chmod a+x myscript.py Added to my crontab -e: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO="" * * * * * /home/me/project/myscript.py My /var/log/cron file says: Sep 21 11:53:02 163-dhcp /USR/SBIN/CROND[2489]: (me) CMD (/home/me/project/myscript.py) But my script is not running because when I check my sql database, nothing has changed. If I run it directly in the terminal like so: python /home/me/project/myscript.py I get the correct

How to pass in password to pg_dump?

只愿长相守 提交于 2019-11-27 10:02:57
I'm trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs: 0 3 * * * pg_dump dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz Except after running that, it expects me to type in a password. I can't do that if I run it from cron. How can I pass one in automatically? araqnid Create a .pgpass file in the home directory of the account that pg_dump will run as. See Postgresql documentation libpq-pgpass for details of the format (including the last paragraph where it explains it will be ignored if you

cron job not working for xwindow

♀尐吖头ヾ 提交于 2019-11-27 08:57:43
问题 I have following line in crontab */1 * * * * xeyes it does not show any xwindow but on the contrary */1 * * * * touch somefile.txt works fine Tried to search on google but didnt get any specific answers!! 回答1: You have to tell cron where to find the X server if the command you run uses it. So use: env DISPLAY=:0.0 xeyes or export DISPLAY=:0.0; xeyes . Some cron implementations (Debian, Ubuntu, ...) allows to set enviroment simply in cron file. DISPLAY=:0.0 # m h dom mon dow command */1 * * *

Cron job: how to run a script that requires to open display?

与世无争的帅哥 提交于 2019-11-27 07:14:13
问题 I want to set up a cron job to run a python script, but it gives me this error: RuntimeError: could not open display This is because I import a module that requires me to open display ( pylab , for example). Even though my script does not generates any pictures to display on the monitor. Is there any way to let crontab run my jobs with display open (just as if I ssh -X into a machine)? I don't actually need to generate any graphs to the monitor. I just need to import my modules correctly. 回答1

Crontab fails to execute Python script

情到浓时终转凉″ 提交于 2019-11-27 06:52:04
问题 crontab fails to execute a Python script. The command line I am using to run the Python script is ok. These are solutions I had tried: add #!/usr/bin/env python at the top of the main.py add PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin at the top of crontab chmod 777 to the main.py file service cron restart my crontab is: PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin */1 * * * * python /home/python_prj/main.py and the log in /var/log/syslog is: Nov 6 07:08:01 localhost CRON[28146]:

Specifying “all odd values” in crontab?

人走茶凉 提交于 2019-11-27 05:41:32
问题 In crontab, I can use an asterisk to mean every value, or "*/2" to mean every even value. Is there a way to specify every odd value? (Would something like "1+*/2" work?) 回答1: Depending on your version of cron, you should be able to do (for hours, say): 1-23/2 Going by the EXTENSIONS section in the crontab(5) manpage: Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9". For a more portable solution, I suspect you just have to use the simple list: 1,3,5,7,9,11,13,15,17,19,21,23