crontab

Linux - cron - 基础

安稳与你 提交于 2019-12-09 13:24:05
概述 cron 相关的理解与使用 背景 最近实在没啥写的了 我写东西, 一般是是这些 看了书过后, 做一些系统的整理 比如之前的 docker 和 git 系列 遇到了实际问题, 解决过程也不是那么顺利, 中间经历了一些求助与试错 一般就是先看异常, 再去百度, 找到有网友的解决方案, 自己照着做一遍, 然后洗稿... 最近在回顾 jojo 的奇妙冒险 里面一众时间系的能力, 让我大呼牛逼 于是, 在这个暂时找不到东西写的时间里, 我决定写一下 cron 兄弟, 能划水的东西写一个, 少一个, 你得加紧看书啊.. 回想起早年的一些遗留问题 我用 cron, 用 crontab 命令写配置 能用但是查不到配置 我同事直接在 /etc/crontab 下写配置 当然能用 还比我的简单 是时候整理一下了 准备 os centos 7 1. 一些场景 概述 列举一些场景 场景 我想在 某个特定的时间, 做某件事 比如 在 2019-12-31 23:59:59, 打印一句 Goodbye 2019 在 2019-12-07 22:42:18, 定时开机 你这是在为难我 linux 不过定时关机, 貌似是可以 我想在 按照某个特定的频率, 执行某个操作 比如 在 每一秒, 打印一下当前时间 在 每分钟的 30 秒, 打印时间 在 每小时的 30 分, 打印时间 在 每一天的 18 点,

Call function periodically in Java

血红的双手。 提交于 2019-12-09 12:11:36
问题 we need run one function periodically in Java web application . How to call function of some class periodically ? Is there any way that call function when some event occured like high load in server and so on . what is crontab ? Is that work periodically ? 回答1: To call something periodically, see TimerTask 回答2: If you need something more robust you can use Quartz As for crontab is the scheduling tool on Unix machines. 回答3: For calling methods when server has high load, you have at least two

How to redirect stderr to a file in a cron job

♀尐吖头ヾ 提交于 2019-12-09 08:49:02
问题 I've got a cron job that is set up like this in my crontab: */1 * * * * sudo /home/pi/coup/sensor.py >> /home/pi/sensorLog.txt It puts stdout into sensorLog.txt, and any stderr it generates gets put into an email. I want both stdout and stderr to go into sensorLog.txt, so I added 1>&2 to the crontab, which is supposed to make stderr go into the same place as stdout. It now looks like this: */1 * * * * sudo /home/pi/coup/sensor.py >> /home/pi/sensorLog.txt 1>&2 Now, both stdout and stderr both

crontab with wget - why is it running twice?

帅比萌擦擦* 提交于 2019-12-09 08:13:49
问题 I've a php script which runs from webservice and insert to DB. crontab -e ......other cron tasks above....... ... .. .. # Run test script.php at 1610 10 16 * * * /usr/bin/wget -q -O /home/username/my_cronjobs/logs/cron_adhoc http://localhost/project/script.php Apparently, at 16:10, this script is run twice! 16:10:01 and 16:25:02 Is it something wrong and gotta do with using wget?? Or did i set the schedule on cron job wrongly? When i run http://localhost/project/script.php from browser, it

Cron job to run every 1st day of the month [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-09 06:01:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I need to create a cron job that will run on the every 1st day of the month every minute of this day. I will create it from cpanel. Any help is appreciated. Thanks 回答1: The crontab entry should look like this : * * 1 * * cmd_to_run The columns mean every minute every hour 1st day of month every month any day of

shell script not running via crontab, runs fine manually

喜夏-厌秋 提交于 2019-12-08 21:33:48
问题 I have tried exporting my paths and variables and crontab still will not run my script. I'm sure I am doing something wrong. I have a shell script which runs a jar file. This is not working correctly. After reading around I have read this is commonly due to incorrect paths due to cron running via its own shell instance and therefore does not have the same preferences setup as my profile does. Here is what my script looks like today after several modifications: #!/bin/bash -- . /root/.bash

Crontab - Restart apache every 3 hours [closed]

你。 提交于 2019-12-08 19:47:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . My server is currently suffering from some problems due to visitors lag and i think the best solution for it, is to restart apache every 2/3 hours or so How can i do this through cronjob ? 回答1: Why do you want to do this?If you are experiencing a specific problem with Apache.It Will definitely be more beneficial

centos crontab定时任务用法

我只是一个虾纸丫 提交于 2019-12-08 16:49:27
centos crontab定时任务用法 一、安装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

How to set a Cron job in Every one hour from 9:00 am to 6:00 pm ( Monday to Friday )

孤者浪人 提交于 2019-12-08 13:57:56
问题 How to set a Cron job in Every one hour from 9:00 am to 6:00 pm ( Monday to Friday) I am using Hostgator cron job to send mail every one hour, Now I want it from Monday to Friday. below is the link to screen shot. http://awesomescreenshot.com/0123cmfxe1 Please help me. 回答1: This should work: 0 9-18 * * 1-5 /path_to_script EDIT: In the format of the boxes it would be 0 9-18 * * 1-5 来源: https://stackoverflow.com/questions/25424102/how-to-set-a-cron-job-in-every-one-hour-from-900-am-to-600-pm

Unable to find SqlPlus processes running when executing shell script via Crontab

此生再无相见时 提交于 2019-12-08 12:12:49
问题 I have a shell script that's being executed via Crontab. The shell script is properly creating the Sqlplus jobs and they run to completion. What's not working is the while loop at the end where I want the script to wait for all of the Sqlplus jobs to complete. If I execute this shell script manually, the while loop at the end works properly and the shell script won't exit until all the Sqlplus jobs have finished. How do I get the while loop at the end to see the Sqlplus jobs while running via