crontab

linux如何执行定时任务

吃可爱长大的小学妹 提交于 2019-12-04 13:29:33
前言 :最近在做一个前端监控系统,用到分表分库的功能,由于代码上无法做到实时新建表,所以只能够曲线救国,使用linux系统的定时任务来完成。 ===================================================================== 安利一下我的开源项目 : 前端监控系统 ===================================================================== 一、如何创建一个脚本 先写一个简单的shell命令: 1. 使用pwd命令查看当前路径为/root目录: 2. 使用vi编辑器 可以直接输入命令$: vim hello.sh 编写第一个shell文件 hello.sh, 请以.sh结尾 以“#”开头的为注释行,不会被执行。 [ #!/bin/bash ] 作为shell脚本文件的开头, [ echo "你好, www.webfunny.cn !" ] 表示打印这句话。 [ node -v ] 表示查看node版本号 3. 执行命令$:chmod 755 hello.sh,通过chmod命令赋予该脚本的执行权限,否则没有执行权限。 执行命令$:/root/hello.sh 表示在全路径下执行该shell脚本。 到此,第一个简单的脚本就完成了。 下边我们就开始创建定时任务了。

通过crontab监控SparkStreaming任务运行状态

99封情书 提交于 2019-12-04 12:13:53
1.问题 最近发现SparkStreaming提交的job经常在半夜挂掉,于是写了个定时任务监控SparkStreaming的运行状态,保证其不挂掉 2.shell脚本 touch /opt/module/jobs/monitorlog.txt vim /opt/module/jobs/monitor.sh #!/bin/bash #在linux中查找你所运行的spark任务中 任务名称为WBStreamingClusterDriver的任务有没有,如果有则返回值是1 job_status=$(yarn application -list| awk '{print $2}' | grep KeyBehaviorsQl | wc -l) if [ $job_status = 0 ];then echo $(date "+%Y-%m-%d %H:%M:%S") 'SparkStreamingTestis stop' >> /opt/module/jobs/monitorlog.txt nohup spark2-submit --master yarn --deploy-mode cluster --driver-memory 3g --num-executors 70 \ --executor-cores 2 --executor-memory 3g \ --class com

Cron job run every x weeks and on specific days [closed]

。_饼干妹妹 提交于 2019-12-04 11:49:44
问题 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 . I want to create a cron job that runs every x weeks and on a specific weekdays. for example: run every 2 weeks on midnight every Sunday and Monday. the cron expression is stored for every "plan" and i use ncrontab function in SQL Server 2008 to generate the dates of given cron expression. Is there an expression

linux定时crontab详解及例子

笑着哭i 提交于 2019-12-04 11:28:35
crontab_test 脚本内容 echo "hello" >> /home/hadoop/shell/result 2>&1 查看/home/hadoop/shell/result文件有多少条数据 cat /home/hadoop/shell/result | wc -l cat /home/hadoop/shell/result | wc -l | wc -l wc -l统计行数,数据来源是|(重定向符号)之前linux命令执行的结果。 crond是什么? crond是linux系统中用来定期执行命令或者指定程序的一种服务或者软件。 可以把crond理解为闹钟服务,有定时叫主人起床的功能。 用rpm -qa | grep crontab查看是否安装,如果没有安装就执行 yum install -y crontabs crond服务操作命令   service crond start //启动服务   service crond stop //关闭服务   service crond restart //重启服务   service crond reload //重新载入配置 cron表达式讲解: * *  *  *  *  command 分钟(0-59) 小时(0-23) 日期(1-31) 月份(1-12) 星期(0-6,0代表星期天)  命令   第1列表示分钟1~59

Linux定时任务

久未见 提交于 2019-12-04 11:25:45
1、crontab命令 crontab [-u username] [-l | -e | -r] -u:只有root才能进行这个任务,帮其他用户新建、删除crontab工作调度 -e:编辑crontab的工作内容 -l:查阅crontab的工作内容 -r:删除所有的crontab工作内容,若仅要删除一项,请用-e去编辑 2、定时任务 crontab -e 0 12 * * * /home/user/aa.sh >>/home/user/aa.log 分 时 日 月 周 命令 0-59 0-23 1-31 1-12 0-7 命令 0或7都表示星期天 辅助字符: * 1,2 8-12 / 3、crontab服务 必须使用root用户启动crond服务,crontab才可以使用 service crond start service crond status 来源: https://www.cnblogs.com/myheart-new/p/11857973.html

7

醉酒当歌 提交于 2019-12-04 09:46:09
Linux-day07 定时任务 crond 系统级别 :定时文件清理,日志切割,定时收集系统的状态 用户级别 :同步系统时间,定时备份数据 定时任务相关的文件 [root@qls ~]# [root@qls ~]# ll /etc/cron* -d drwxr-xr-x. 2 root root 21 Aug 14 15:11 /etc/cron.d drwxr-xr-x. 2 root root 42 Aug 14 15:12 /etc/cron.daily #系统每天执行定时任务 -rw-------. 1 root root 0 Apr 11 2018 /etc/cron.deny #黑名单 drwxr-xr-x. 2 root root 22 Aug 14 15:11 /etc/cron.hourly #系统每小时 drwxr-xr-x. 2 root root 6 Jun 10 2014 /etc/cron.monthly #系统每个月 -rw-r--r--. 1 root root 451 Jun 10 2014 /etc/crontab #定时任务的主配置文件 drwxr-xr-x. 2 root root 6 Jun 10 2014 /etc/cron.weekly #系统每周 /var/spool/cron/ #用户定时任务存放地址 [root@qls ~]#

Difference between using Message Queue vs Plain Cron Jobs with PHP

蓝咒 提交于 2019-12-04 09:34:44
问题 We have a large web application built on PHP. This application allows scheduling tweets and wall posts and there are scheduled emails that go out from the server. By 'scheduled', I mean that these are PHP scripts scheduled to run at particular time using cron . There are about 7 PHP files that do the above jobs. I have been hearing about Message Queues. Can anyone explain if Message Queues are the best fit in this scenario? Do Message Queues execute PHP scripts? or do we need to configure

Ansible之常用模块(二)

社会主义新天地 提交于 2019-12-04 09:29:41
  1、hostname:此模块的主要作用是管理远端节点主机名 模块帮助: root@localhost ~]# ansible-doc -s hostname - name: Manage hostname hostname: name: # (required) Name of the host [root@localhost ~]#   说明:通常我们使用这个模块是在playbook里使用,通过一些变量的控制,给定不同的主机以不同的主机名。 常用参数说明:   name:指定远端节点主机名称 [root@localhost ~]# ansible 192.168.0.99 -m shell -a 'hostname' 192.168.0.99 | SUCCESS | rc=0 >> docker [root@localhost ~]# ansible 192.168.0.99 -m hostname -a 'name=test' 192.168.0.99 | SUCCESS => { "ansible_facts": { "ansible_domain": "", "ansible_fqdn": "test", "ansible_hostname": "test", "ansible_nodename": "test" }, "changed": true, "name":

Enable/Disable tasks in Crontab by Bash/Shell

瘦欲@ 提交于 2019-12-04 08:47:43
问题 Is there a way to enable and disable Crontab tasks using Bash/Shell? So when the user starts Server 1, it will enable the Server 1 Crontab line and so on. And when the user stops Server 1, the Server 1 Crontab line get disabled (#). Is this possible and how? Thanks in advance */1 * * * * Server 1 check */1 * * * * Server 2 check */1 * * * * Server 3 check 回答1: SERVERNUM=$1 To enable: crontab -l | sed "/^#.*Server $SERVERNUM check/s/^#//" | crontab - To disable: crontab -l | sed "/^[^#].

定时任务crontab

烈酒焚心 提交于 2019-12-04 08:13:14
1. crontab循环执行定时任务 1.1 crond服务管理与控制访问   crontab命令是需要crond服务支持的,crond服务同样是独立的服务。 crond服务默认是自启动的。 [root@centos2 ~]# systemctl status crond ● crond.service - Command Scheduler Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled) Active: active (running) since 三 2019-11-13 16:24:18 CST; 2h 24min ago Main PID: 1267 (crond) Tasks: 1 CGroup: /system.slice/crond.service └─1267 /usr/sbin/crond -n 11月 13 16:24:18 centos2 systemd[1]: Started Command Scheduler. 11月 13 16:24:19 centos2 crond[1267]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 17% if used.) 11月 13