crontab定时任务2_net
crontab定时任务2_net
1、先来一个小小的例子
查看当前路径:
[root@root test]# pwd
/home/admin/test
[root@root test]# crontab -l
查看当前用户的定时任务 也可以 crontab -uroot -l查看指定用户的定时任务。
千万不要忘了中间的 sh 表示用户拿什么来执行命令
00 02 * * * sh /home/admin/optbash/dailyBackup.sh
00 02 * * * sh /home/admin/optbash/deleteDebugSql.sh
建立一个用定时任务跑的bash脚本:
[root@root test]# touch test.sh
[root@root test]# vim test.sh
编辑如下内容,将系统当前时间输出到 console.txt 文件然后保存,增加可执行权限
/bin/echo `date` > /home/admin/test/console.txt
[root@root test]# ll
total 8
-rw-r--r-- 1 root root 29 Mar 27 21:31 console.txt
-rwxr-xr-x 1 root root 48 Mar 27 21:28 test.sh
[root@root test]# chmod +x ./test.sh
追加 crontab 定时任务,每分钟触发:
[root@root test]# crontab -e
00 02 * * * sh /home/admin/optbash/dailyBackup.sh
00 02 * * * sh /home/admin/optbash/deleteDebugSql.sh
* * * * * sh /home/admin/test/test.sh
前面是已经存在的定时任务,后面执行test.sh脚本的是追加的 保存后提示已经装载了新的定时任务
"/tmp/crontab.HauiiV" 3L, 143C written
crontab: installing new crontab
再次查看定时任务列表,可以看到定时任务已经添加
[root@root test]# crontab -l
00 02 * * * sh /home/admin/optbash/dailyBackup.sh
00 02 * * * sh /home/admin/optbash/deleteDebugSql.sh
* * * * * sh /home/admin/test/test.sh
[root@root test]#
查看console.txt有没有每分钟写入console.txt文件
[root@root test]# vim console.txt
Fri Mar 27 21:40:01 EDT 2015
可以看到最近一次的写入时间。
2、看看crontab 的时间表达式
基本格式 :
* * * * * command
分 时 日 月 周 命令
然后来几个实际的例子:
1、每分钟执行一次
* * * * *
2、每隔一小时执行一次
00 * * * *
or
* */1 * * * (/表示频率)
3、每小时的15和30分各执行一次
15,45 * * * * (,表示并列)
4、在每天上午 8- 11时中间每小时 15 ,45分各执行一次
15,45 8-11 * * * command (-表示范围)
5、每个星期一的上午8点到11点的第3和第15分钟执行
3,15 8-11 * * 1 command
6、每隔两天的上午8点到11点的第3和第15分钟执行
3,15 8-11 */2 * * command
3、其他命令介绍
名称 : crontab
使用权限 : 所有使用者
使用方式 :
crontab file [-u user]-用指定的文件替代目前的crontab。
crontab-[-u user]-用标准输入替代目前的crontab.
crontab-1[user]-列出用户目前的crontab.
crontab-e[user]-编辑用户目前的crontab.
crontab-d[user]-删除用户目前的crontab.
crontab-c dir- 指定crontab的目录。
4、crond 安装与配置服务
安装crontab:
yum install crontabs
服务操作说明:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
查看crontab服务状态:
service crond status
手动启动crontab服务:
service crond start
查看crontab服务是否已设置为开机启动,执行命令:
ntsysv
加入开机自动启动:
chkconfig –level 35 crond on
crontab定时任务2_net的更多相关文章
- Linux下实现秒级的crontab定时任务
crontab的格式如下 * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 ...
- 【转】crontab定时任务中文乱码问题
转载:http://blog.163.com/rettar@126/blog/static/1216503422012135511740/ 手动执行都很正常的的脚步,添加到定时任务中一直执行失败,日志 ...
- Linux crontab 定时任务
http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html 19. crontab 定时任务 通过crontab 命令,我们 ...
- crontab 定时任务格式
如下内容节选自<Linux Crontab 定时任务 命令详解> 用crontab -e 添加要执行的命令 添加的命令必须以如下格式: * * * * * /command path 前五 ...
- scrapy使用crontab定时任务不能自动执行的调试
在用crontab进行定时任务时,发现任务并没有执行.而手动bash yourshell.sh时可以正常的执行程序.以下是个人的解决流程. 一.将错误打印打out.log */10 * * * * b ...
- 对于crontab定时任务不能自动执行的总结
最近遇到了一些sh不能在crontab定时任务中自动执行的问题 期间由于不太了解,故走了一点弯路,现在总结下来可能第一次 进行设置遇到的问题.以绝后患!我所用过的操作系统为HP-unix&li ...
- crontab定时任务不执行的原因
1.重启crontab若是遇见"You (cloudlogin) are not allowed to use this program (crontab) ...
- Linux下Crontab定时任务的使用教程 以及 无法执行定时任务的解决方案
前言 本文学习思路:Linux的corntab定时任务的使用教程 --> 定时任务无效的解决方案 Linux的corntab定时任务的使用教程 1. 首先,输入命令 打开crontab定时 ...
- 使用linux下的crontab定时任务跑定时脚本
使用linux下的crontab定时任务跑定时脚本 tags:定时任务 定时脚本 crontab linux定时脚本 linux 引言:应该有许多人曾经很好奇一些定时脚本是怎么做出来的.我们这次就来说 ...
随机推荐
- wordpress 5.1 后台拿shell
闲着没事搭建了一套最新版wordpress 5.1,本身wordpress后台安全防御是比较差的,想尝试下后台是否可以拿shell. 再上传插件的地方可以直接上传php文件,并且该文件可以执行: sh ...
- ini_set的用法介绍
https://www.cnblogs.com/xieqian111/p/5367732.html
- redis启动停止+密码认证
redis启动停止命令 ./bin/redis-server redis.conf ./bin/redis-cli -h 127.0.0.1 -p 6379 shutdown flushall ——& ...
- Final互评------《弹球学成语》---- 杨老师粉丝群
一.基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题; N(Need,需求):本产品面相青少年及小学生,基于这些用户数量再加上一些休闲玩家,需求量还是比较大的. A ...
- 团队作业Week5
每个团队开一个讨论会,协商讨论团队贡献分的分配方式.每个团队的团队贡献分为50分/人.每个人分数不能相同,请详细说明分数的分配规则. 可参考这个博客. 截止时间:2014-10-27
- 每日scrum(4)
今天是冲刺第4天,大家都忙着找大二的学弟学妹来点评来支持我们的软件. 遇到的问题主要是如何劝说学弟学妹选择我们的软件然后继续往下做. 任务看板: 燃尽图:
- 完善好的web项目(校园包车)
- We're Chronos! ----- Meet the team 团队作业 #1
Meet Us —————————————————La ligne de séparation————————————————— Kane Lim [林珣玙] < PM, Programmer ...
- Linux 系统目录
/ 根目录 /bin 存放必要的命令 /boot 存放内核以及启动所需的文件等 /dev 存放设备文件 /etc 存放系统的配置文件 /home 用户文件的主目录,用户数据存放在其主目录中 /lib ...
- layout图形化界面看不到内容 Failed to find the style corresponding to the id
1.问题 在创建新的工程的时候,选择目标SDK为api21,编译SDK为api23.创建出来的layout文件图形化界面中看不到,并且报错: Failed to find the style corr ...