crontab

Linux计划任务及压缩归档

时间秒杀一切 提交于 2019-11-28 10:12:51
计划任务介绍 我们可以通过一些设置。来让电脑定时提醒我们该做什么事了。或者我们提前设置好,告诉电脑你几点做什么几点做什么,这种我们就叫它定时任务。而遇到一些需要执行的事情或任务。我们也可以通过命令来告诉电脑一会临时把这个工作给做一下 总结:在我们LINUX中,我们可以通过crontab和at这两个东西来实现这些功能的 计划任务的作用:是做一些周期性的任务,在生产中的主要用来定期备份数据 计划任务的安排方式分两种: 一种是定时性的,也就是例行。就是每隔一定的周期就要重复来做这个事情 一种是突发性的,就是这次做完了这个事,就没有下一次了,临时决定,只执行一次的任务 at和crontab这两个命令: at:它是一个可以处理仅执行一次就结束的指令 crontab:它是会把你指定的工作或任务,比如:脚本等,按照你设定的周期一直循环执行下去 at一次性计划任务使用 at语法格式:at 时间 下载at程序 [root@ken ~]# yum install at -y 启动atd服务 [root@ken ~]# systemctl restart atd [root@ken ~]# ps aux | grep atd root 1166 0.0 0.1 25904 944 ? Ss 17:52 0:00 /usr/sbin/at -f root 1168 0.0 0.1 112704 956

How to run a Shell Script by Cron Job

两盒软妹~` 提交于 2019-11-28 09:00:38
问题 I have a Shell script like below echo "Hello World" The script is located in /root/scripts/ folder as test.sh I also created a cron job like below 0-59 * * * * ./scripts/test.sh Now the cron job is not printing the content in test.sh every minute. Let me know whether I have given a wrong directory or I have any other problem in my code. 回答1: I would Be explicit wrt. your directory to execute from e.g. /root/scripts/test.sh . I don't know what cron would regard as the current directory

php cron job not running [duplicate]

我只是一个虾纸丫 提交于 2019-11-28 08:29:19
问题 This question already has answers here : cronjob does not execute a script that works fine standalone (2 answers) Closed 3 years ago . root@xx:/var/www/test# which php /usr/bin/php root@xx:/var/www/test# ls -la total 16 drwxrwxrwx 2 root root 4096 Nov 14 09:37 . drwxrwxrwx 6 root root 4096 Nov 13 15:51 .. -rwxrwxrwx 1 root root 153 Nov 14 09:35 test.php This is my test.php file: <?php $my_file = 'file.txt'; $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); //implicitly

Python Script not running in crontab calling pysaunter

拜拜、爱过 提交于 2019-11-28 07:54:52
问题 I have read multiple posts and many articles detailing that scipts in a cron job need to keep the environment variables necessary to run inside the script itself due to the opening of shells within cron. My situation is unique in that my path variables are all being set as discussed, which in turn will successfully call the pysaunter python egg using subprocess.call(), but it seems to break down from there. This causes the whole process to break in a cron job. For clarity, here are the steps

mysqldump doesn't work in crontab

╄→гoц情女王★ 提交于 2019-11-28 07:33:50
I'm trying to add a cronjob in the crontab (ubuntu server) that backups the mysql db. Executing the script in the terminal as root works well, but inserted in the crontab nothing happens. I've tried to run it each minutes but no files appears in the folder /var/db_backups. (Other cronjobs work well) Here is the cronjob: * * * * * mysqldump -u root -pHERE THERE IS MY PASSWORD --all-databases | gzip > /var/db_backups/database_`date +%d%m%y`.sql.gz what can be the problem? You need to escape % character with \ mysqldump -u 'username' -p'password' DBNAME > /home/eric/db_backup/liveDB_`date +\%Y\%m

crontab定时任务

自作多情 提交于 2019-11-28 07:18:23
apt-get install cron #安装Crontab /etc/init.d/cron restart #重启Crontab crontab -e #编辑定时任务 crontab -r #移除定时任务 crontab -l #查看定时任务 判断crond 是否在运行:pgrep crond或者pgrep cron,如果有在运行则返回进程号。 * * * * * /usr/local/php56/bin/php 项目路径/artisan schedule:run >> /dev/null 2>&1 /dev/null日志抛出不打印,也可以写个日志输入的路径/home/test.txt 来源: https://blog.csdn.net/xiaomei__/article/details/100030896

Specifying “all odd values” in crontab?

时间秒杀一切 提交于 2019-11-28 07:07:28
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?) 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 But it might be easier to wrap your command in a shell script that will immediately exit if it's not called in

Linux-排JOB定时任务

爱⌒轻易说出口 提交于 2019-11-28 05:47:50
   排job的3种方法,at方法只能执行一次,crontab可循环执行比较灵活,anacrontable可以检测job是否正常执行,没有执行就会重新执行比较智能一些,但是要执行的指令脚本要 放到相应的houly,daily文件夹下。 at at只能执行一次,使用这个指令有白名单,黑名单控制。 Crontab 使用这个指令一样有白名单和黑名单,crontab -e后在文件中配置job, 格式:* * * * * 指令 **是执行计划,什么时候执行,后面跟要执行的脚本指令,创建时自动指定当前用户账号 anacrontab 与crontab类似,但是会记录每次跑的时间,超出间隔没跑,会补跑,vim anacrontab 配置文件,按每小时每天执行相应文件夹下的脚本 来源: https://www.cnblogs.com/JinweiChang/p/11395228.html

How can i set a crontab to execute a mysql query and log the output?

大兔子大兔子 提交于 2019-11-28 05:00:02
问题 Well, title self describes it.. I need to run a sql function to clean some duplicated posts, i need to do it several times a day so i need to use cron... I set a new crontab job, like this: 00 16,18,19,20,21 * * * mysql -h MY-DB-HOST.COM -u MY-DB-USERNAME -pMY-DB-PASSWORD -e "delete from hotaru_posts where post_id in ( select post_id from ( select post_id from hotaru_posts a group by post_title having count(post_title) > 1 ) b )" >> /tmp/cron_job.log but nothing seems to be logged, so i

Linux-定时任务

假如想象 提交于 2019-11-28 03:57:41
/*--> */ /*--> */ 第17章 Linux系统管理-定时任务 第17章 Linux系统管理-定时任务 1. 定时任务基本概述 2. 定时任务管理 3. 定时任务实战 4. 定时任务课堂练习题 5. 定时给小姐姐发情书 6. 定时任务编写思路 7. 总结:9句箴言 1. 定时任务基本概述 01. 什么是定时任务? xxxxxxxxxx ​ 设定某个日期或时间周期性执行指令。比如设定一个闹铃,叫你每天早上7点钟起床等,这就是一个定时任务。 ​ 02. 什么是crond? xxxxxxxxxx ​ crond是linux系统中用来定期执行命令或脚本的一种服务软件,一般情况下,我们安装完centos操作系统之后, 默认便会启动Crond任务调度服务。 ​ crond服务会定期(默认每分钟检查一次)检查系统中是否有要执行的任务工作,如果有,便会根据其预先设定的定 时任务规则自动执行该定时任务工作,这个crond定时任务服务就相当于我们平时早起使用的闹钟一样。 ​ 03. 为什么要使用定时任务? xxxxxxxxxx ​ 我们举个例子说明:例如,我们的数据库或者代码程序需要每天晚上0点做一次备份,这样每天夜里都需要执行的周期性工作,如果要让人操作的话,就得每天半夜爬起来,然后登录系统执行任务,执行完接着睡觉。另外,执行任务的过程也可能持续几个小时,这样一来