crontab

Cannot run bash script from crontab when it works from command line bash

拜拜、爱过 提交于 2019-11-27 16:36:20
问题 I have a strange problem of being to able to run a bash script from commandline but not from the crontab entry for root. I am running Ubuntu 12.04. * * * * 1-5 root /home/xxxxxx/jmeter/VerificationService-0.0.1-SNAPSHOT/jmeter-cron-randomise.sh >> /home/xxxxxxx/jmeter/VerificationService-0.0.1-SNAPSHOT/cron.log If I run the script from the cmd line using bash, it works fine but sh fails with following error: > jmeter-cron-randomise.sh: 7: jmeter-cron-randomise.sh: arithmetic > expression:

Run every 2nd and 4th Saturday of the month

余生长醉 提交于 2019-11-27 16:16:27
问题 What's the cron (linux) syntax to have a job run on the 2nd and 4th Saturday of the month? 回答1: The second Saturday of the month falls on one (and only one) of the dates from the 8 th to the 14 th inclusive. Likewise, the fourth Saturday falls on one date between the 22 nd and the 28 th inclusive. You may think that you could use the day of week field to limit it to Saturdays (the 6 in the line below): 0 1 8-14,22-28 * 6 /path/to/myscript Unfortunately, the day-of-month and day-of-week is an

Linux下的crontab定时执行任务命令详解

做~自己de王妃 提交于 2019-11-27 16:10:20
来自: https://www.cnblogs.com/longjshz/p/5779215.html 在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron]。cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间。 cron的配置文件称为“crontab”,是“cron table”的简写。 一、cron服务   cron是一个linux下 的定时执行工具,可以在无需人工干预的情况下运行作业。   service crond start //启动服务   service crond stop //关闭服务   service crond restart //重启服务   service crond reload //重新载入配置   service crond status //查看服务状态 二、cron在3个地方查找配置文件: 1、/var/spool/cron/ 这个目录下存放的是每个用户包括root的crontab任务,每个任务以创建者的名字命名,比如tom建的crontab任务对应的文件就是/var/spool/cron/tom。一般一个用户最多只有一个crontab文件。 三、/etc/crontab 这个文件负责安排由系统管理员制定的维护系统以及其他任务的crontab。 SHELL=/bin/bash

crontab 常见 /dev/null 2>&1 详解

三世轮回 提交于 2019-11-27 15:10:27
大部分在 crontab 计划任务中都会年到未尾带 >/dev/null 2>&1,是什么意思呢? > 是重定向 /dev/null 代表空设备文件 1 表示stdout标准输出,系统默认值是1,所以 ">/dev/null" 等同于 "1>/dev/null" 2 表示stderr标准错误 & 表示等同于的意思,2>&1,表示2的输出重定向等同于1 整句的意思就是标准输出重定向到空设备文件,也就是不输出任何信息到终端,标准错误输出重定向等同于标准输出,因为之前标准输出已经重定向到了空设备文件,所以标准错误输出也重定向到空设备文件 command > file 2>file 与 command > file 2>&1 有什么区别呢? command > file 2>file 的意思是将命令所产生的标准输出信息,和错误的输出信息送到file 中.command > file 2>file 这样的写法,stdout和stderr都直接送到file中, file会被打开两次,这样stdout和stderr会互相覆盖,这样写相当使用了FD1和FD2两个同时去抢占file 的管道. 而command >file 2>&1 这条命令就将stdout直接送向file, stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1

linux之crontab

♀尐吖头ヾ 提交于 2019-11-27 14:01:13
查看任务 crontal -l 编辑任务 1 crontab -e 编辑crontab文件 1 vim /etc/crontab 1 SHELL=/bin/bash 2 PATH=/sbin:/bin:/usr/sbin:/usr/bin 3 MAILTO=root 4 5 # For details see man 4 crontabs 6 7 # Example of job definition: 8 # .---------------- minute (0 - 59) 9 # | .------------- hour (0 - 23) 10 # | | .---------- day of month (1 - 31) 11 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 12 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 13 # | | | | | 14 # * * * * * user-name command to be executed 语法 crontab任务配置基本格式: * *  *  *  *  command 分钟(0-59) 小时(0-23) 日期(1-31) 月份(1

Ubuntu查看crontab运行日志

走远了吗. 提交于 2019-11-27 14:00:40
crontab记录日志 修改rsyslog sudo vim /etc/rsyslog.d/50-default.conf cron.* /var/log/cron.log #将cron前面的注释符去掉 重启rsyslog sudo service rsyslog restart sudo service cron restart 查看crontab日志 less /var/log/cron.log 来源: https://www.cnblogs.com/ahuo/p/11366704.html

Crontab Formatting - every 15 minutes

拥有回忆 提交于 2019-11-27 13:56:15
I'm trying to get a simple crontab job to run every 15 minutes and am having trouble deciding how to format the timing. What I've been putting down is the following: 15 * * * * ------------------------ I'm pretty sure this just runs the first 15 minutes of every hour. I think that crontab allows users to specify exact times to run, namely: 0, 15,30,45 * * * * ------------------------- But if I wanted to run the crontab every 15 minutes from the moment I start it, (which may not necessarily be on a value divisible by 15), how would I go about formatting that/is that possible? Crontab doesn't

批量删除文件,只保留目录下最新的几个文件,其他均删除

ぃ、小莉子 提交于 2019-11-27 13:55:30
1、新建删除脚本 del.sh #!/bin/bash #保留文件数 ReservedNum=5 ##保留最新的五个文件 FileDir=/data/bak ##文件目录 date=$(date "+%Y%m%d-%H%M%S") FileNum=$(ls -l $FileDir|grep ^- |wc -l) while(( $FileNum > $ReservedNum)) do OldFile=$(ls -rt $FileDir| head -1) echo $date "Delete File:"$OldFile rm -rf $FileDir/$OldFile let "FileNum--" done 2、添加自动运行任务crontab 如果未安装crontab,先安装 yum install crontabs -y 添加自动运行任务 crontab -e * 0 * * * bash /home/sh/del.sh 意思是每天凌晨0点,自动运行 /home/sh文件夹下的del.sh脚本 查看任务 crontab -l 来源: https://www.cnblogs.com/xiaoyou2018/p/11750507.html

linux中crontable的用法 附件二

三世轮回 提交于 2019-11-27 13:01:55
linux中crontable的用法 2013年09月24日 ⁄ 综合 ⁄ 共 4104字 ⁄ 字号 小 中 大 ⁄ 评论关闭 crontab命令的功能是在一定的时间间隔调度一些命令的执行。 1.0 新建定时任务 1、 查看crontab服务是否启动 , root@oracle lhq]# serv ice crond status; 2、 启动crontab服务 [root@oracle lhq]# service crond start Starting crond: [ OK ] 3 、查看已经存在的定时任务 [root@oracle lhq]# crontab -l 25 14 * * * mkdir /lhq/test [root@oracle lhq]# 4、添加定时任务 [root@oracle lhq]# crontab -e 1.1 /etc/crontab 文件 在/etc目录下有一个crontab文件,这里存放有系统运行的一些调度 程序 。每个用户可以建立自己的调度crontab。 如: [root@dave ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 01 * * * * root run

Linux 上 curl + crontab 的用处

不打扰是莪最后的温柔 提交于 2019-11-27 12:44:53
1、curl的基本用处 curl最基本的用处是查看网页源代码,如下: 查看源代码的同时实现了一次浏览页面 2、crontab的基本用处 crontab可以实现Linux上的定时任务,基本语法如下: * * * * * command 分钟 小时 日 月 星期 执行的命令 0~59 0~23 1~31 1~12 0~6 比如:每分钟输出一下当前时间的定时任务 1、crontab -e --编辑当前用户的定时任务 每分钟也可写作:*/1 * * * * command 2、crontab -l --列出当前用户的定时任务 3、--查看定时任务执行情况 当前用户定时任务输出在目录/var/spool/mail/下对应的当前用户名文件中,比如当前用户名是dirk,查看当前用户定时任务如下: 3、curl + crontab 写到这里估计你就知道用这两个命令可是做什么事情了吧,用来增+web的visits 1、编写访问指定URL的脚本 sleep 1:当前进程暂停1秒钟,仿正常访问行径 >/dev/null 2>&1:将标准输出和错误输出都重定向/dev/null,也就是系统“黑洞” 2、编写定时任务 2分钟执行一次,是为了防止被禁 sh /root/cron_sh/csdn_to_top.sh:执行上一步编写的脚本 3、查看定时任务执行情况 建议使用:cat /var/spool/mail