[Linux]定时任务

作者: 瑾兰 | 来源:发表于2018-04-27 17:15 被阅读9次
1、vim shell.sh :创建并编辑脚本
#!/bin/bash
DATE=`date`
echo ${DATE} >> /root/lbl.txt   

将日期追加到/root/lbl.txt文件中去

2、chmod 755 shell.sh:修改shell.sh的权限,必须是可执行的
chmod 755 shell.sh
3、vim /etc/crontab:编辑脚本执行时间
cdSHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

*/1 * * * * root /tmp/shell.sh

注意:上面这个文件中只有最后一句指令是我自己添加的:*/1 * * * * root /tmp/shell.sh为每分钟 执行/tmp/shell.sh脚本

4、systemctl restart crond:重启cron服务
systemctl restart crond
5、tail -f lbl.txt: 实时查看lbl.txt文件中输出的内容
tail -f lbl.txt

备注:过程中用到的指令
vim shell.sh:创建并编辑脚本

sh /tmp/shell.sh:手动执行脚本

chown jack:police shell.sh:修改文件所有者

vim /etc/crontab:系统配置

systemctl restart crond:重启cron服务;注意:cron服务是Linux内置服务,默认不会开机自动启动;

tail -f -n200 lbl.txt:实时查看后200行
参考链接
CentOS 7.x cron定时任务服务重启

相关文章

  • day 17

    第13章 Linux系统定时任务Cron(d)服务应用实践 1.1、Linux定时任务 1.1.1、什么是定时任务...

  • linux crontab: 定时任务

    参考 crontab 定时任务 Linux之crontab定时任务

  • linux Crontab

    Linux Crontab:Linux中用于执行定时任务的工具crontab -e:编辑定时任务crontab -...

  • 定时任务

    Linux定时任务 什么是定时任务: 周期性的执行任务计划的软件,linux里定时任务常用软件有:Crond 使用...

  • day17

    Linux系统定时任务 3W1H 框架 Linux系统定时任务: 1、什么是定时任务? 周期性的执行任务计划的软件...

  • day17-Linux系统定时任务

    Linux系统定时任务 1.什么是定时任务? 周期性的执行任务计划的软件,Linux定时任务软件的常用软件cron...

  • 作业-第04周--课堂-Day17-linux系统定时任务Cro

    Day17 课堂笔记 1 Linux系统定时任务 1、什么是定时任务?周期性的执行任务计划的软件,Linux定时任...

  • Linux笔记

    Linux定时任务 Mysql备份 Linux+Mysql定时备份 * * * * * user task分 时 ...

  • 79.linux定时任务

    Linux定时任务 通过制定 ```crontab -e``编辑和开启定时任务

  • Linux定时任务

    Linux定时任务 centOS: 使用crontab -e //编辑 crontab -l //查看定时任务 生...

网友评论

    本文标题:[Linux]定时任务

    本文链接:https://www.haomeiwen.com/subject/chlilftx.html