linux任务计划cron
linux任务计划cron

1.crontab命令任务计划配置文件
[root@bogon ~]# cat /etc/crontab
SHELL=/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 [root@bogon ~]#
2.编辑计划任务crontab -e
[root@bogon ~]# crontab -e
3. 每天三点执行并把正确的和错误的输出到123.log文件中 0 3 * * * /bin/bash /usr/loacl/sbin/123.sh >/tmp/123.log 2>/tmp/123.log,如果是追加将>改成>>会将每天的输出以追加的方式写入文件
4.一号到十号的三点执行0 3 1-10 * * /bin/bash /usr/loacl/sbin/123.sh >/tmp/123.log 2>/tmp/123.log
5.一号到十号的每两个月(能被2整除的月份)三点执行0 3 1-10 */2 * /bin/bash /usr/loacl/sbin/123.sh >/tmp/123.log 2>/tmp/123.log
6.一号到十号的每两个月(能被2整除的月份)的周二和周五三点执行0 3 1-10 */2 2,5 /bin/bash /usr/loacl/sbin/123.sh >/tmp/123.log 2>/tmp/123.log
7.启动并查看crond服务
[root@sunyujun01 ~]# systemctl start crond
[root@sunyujun01 ~]# ps aux|grep crond
root 1393 0.0 0.0 124144 508 ? Ss 09:44 0:00 /usr/sbin/crond -n
root 16427 0.0 0.0 112672 972 pts/2 R+ 11:55 0:00 grep --color=auto crond
[root@sunyujun01 ~]#
8.也可以用systemctl status crond命令查看crond启动状态
[root@sunyujun01 ~]# systemctl status crond
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since 三 2018-01-24 09:44:22 CST; 3h 26min ago
Main PID: 1393 (crond)
CGroup: /system.slice/crond.service
└─1393 /usr/sbin/crond -n 1月 24 09:44:22 localhost.localdomain systemd[1]: Started Command Scheduler.
1月 24 09:44:22 localhost.localdomain systemd[1]: Starting Command Scheduler...
1月 24 09:44:23 localhost.localdomain crond[1393]: (CRON) INFO (Syslog will ...
1月 24 09:44:23 localhost.localdomain crond[1393]: (CRON) INFO (RANDOM_DELAY...
1月 24 09:44:23 localhost.localdomain crond[1393]: (CRON) INFO (running with...
Hint: Some lines were ellipsized, use -l to show in full.
[root@sunyujun01 ~]#
9.停掉crond
[root@sunyujun01 ~]# systemctl stop crond
10.如果脚步中的命令没有执行,可能是命令没有加入到crond变量里面,也可以直接写绝对路径

11.这个文件的内容是crontab -l列出来的计划任务列表,如果备份的话直接拷贝这个文件就行
[root@sunyujun01 ~]# cat /var/spool/cron/root
12.crontab -r 删除
chkconfig工具

1.chkconfig --list查看使用chkconfig工具的服务
[root@sunyujun01 ~]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。 mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
nginx 0:关 1:关 2:开 3:开 4:开 5:开 6:关
php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@sunyujun01 ~]#
2.对应的服务都在/etc/init.d/目录下
[root@sunyujun01 ~]# ls /etc/init.d/
functions mysql netconsole network nginx php-fpm README
[root@sunyujun01 ~]#
3.关闭network服务 chkconfig network off
[root@sunyujun01 ~]# chkconfig network off
[root@sunyujun01 ~]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。 mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:关 3:关 4:关 5:关 6:关
nginx 0:关 1:关 2:开 3:开 4:开 5:开 6:关
php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@sunyujun01 ~]#
4.network的6个级别都变成关闭状态了
5.重新启动network
0 停机
1 单用户模式
2 多用户,没有 NFS
3 完全多用户模式
4 没有用到
5 图形界面
6 重新启动
S s Single user mode
[root@sunyujun01 ~]# chkconfig network on
[root@sunyujun01 ~]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。 mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
nginx 0:关 1:关 2:开 3:开 4:开 5:开 6:关
php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@sunyujun01 ~]#
6.在centos7之前的版本可以通过编辑文件定义系统级别
[root@sunyujun01 ~]# vim /etc/inittab
7. 设定某个运行级别开关
[root@sunyujun01 ~]# chkconfig --level 3 network off
8.也可以写多个345
[root@sunyujun01 ~]# chkconfig --level 345 network off
9.将123服务添加到服务中
[root@sunyujun01 init.d]# cp network 123^C
[root@sunyujun01 init.d]# ls -l
总用量 60
-rwxr-xr-x 1 root root 6630 1月 24 14:17 123
-rw-r--r--. 1 root root 13948 9月 16 2015 functions
-rwxr-xr-x. 1 root root 10880 2月 10 2017 mysql
-rwxr-xr-x. 1 root root 2989 9月 16 2015 netconsole
-rwxr-xr-x. 1 root root 6630 9月 16 2015 network
-rwxr-xr-x. 1 root root 2652 2月 10 2017 nginx
-rwxr-xr-x. 1 root root 2401 2月 10 2017 php-fpm
-rw-r--r--. 1 root root 1160 11月 22 2016 README
[root@sunyujun01 init.d]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。 mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
nginx 0:关 1:关 2:开 3:开 4:开 5:开 6:关
php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@sunyujun01 init.d]# chkconfig --add 123
[root@sunyujun01 init.d]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。 123 0:关 1:关 2:开 3:开 4:开 5:开 6:关
mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
nginx 0:关 1:关 2:开 3:开 4:开 5:开 6:关
php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@sunyujun01 init.d]#
10.删除一个服务
[root@sunyujun01 init.d]# chkconfig --del 123
[root@sunyujun01 init.d]#
systemd管理服务

1.列出所有service服务,如果想列出所有用systemctl list-unit-files
[root@sunyujun01 init.d]# systemctl list-units -all --type=service
unit介绍
1.7个运行级别一一对应的软连接
[root@sunyujun01 system]# ls -l runlevel*
lrwxrwxrwx. 1 root root 15 2月 10 2017 runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 2月 10 2017 runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 2月 10 2017 runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 2月 10 2017 runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 2月 10 2017 runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 2月 10 2017 runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 2月 10 2017 runlevel6.target -> reboot.target

target介绍(一个target是多个unit的组合)

linux任务计划cron的更多相关文章
- linux任务计划cron、chkconfig工具、systemd管理服务、unit和target介绍
第8周第1次课(5月14日) 课程内容: 10.23 linux任务计划cron10.24 chkconfig工具10.25 systemd管理服务10.26 unit介绍10.27 target介绍 ...
- Linux centos7 linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、 target介绍
一.linux任务计划cron crontab -u -e -l -r 格式;分 时 日 月 周 user command 文件/var/spool/corn/username 分范围0-59,时范 ...
- Linux任务计划
Linux任务计划: 一次性任务执行(at.batch): at:定时任务,指定一个时间执行一个任务,只能执行一次. at使用方式: 交互式:让用户在at>提示符输入多个要执行的命令: 批处理: ...
- Linux定时任务系统 Cron
运行计划任务时:service crond restart提示:crond: unrecognized service安装计划任务:yum -y install vixie-cron 另外附计划任务的 ...
- 配置Linux任务计划
Linux有三种计划任务: at:指定一个时间执行一个任务 (适用一个或多个任务,执行一次后就不用) cron:根据一个时间表自动执行任务 (使用一个或多个任务,周期性执行) 系统级别的计划任务及其扩 ...
- linux crontab 计划任务 atd和windows下的计划任务
crontab 命令 如果发现您的系统里没有这个命令,请安装下面两个软件包. vixie-cron crontabs crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类 ...
- Linux操作系统计划任务
++++++++++++++++++++++++++++++++++++++++++++++++标题:Linux操作系统的计划任务内容:计划任务分为单次任务和周期性任务,周期任务分为系统级计划任务和用 ...
- Linux中计划任务、周期性任务设置
Linux中计划任务.周期性任务设置 计划任务:指在未来的特定时间里,执行一次某一特定任务.当然,如果同一任务需要在不同时间点执行执行两次.三次或多次,可以视为多个一次看待. 周期性任务:指某一任务需 ...
- Linux定时任务计划
Linux定时任务计划 在使用Linux系统时,我们有时会需要让系统在某个时间去执行特定的任务,这时就需要去了解Linux提供的定时任务功能 种类 Linux的定时任务分为两种:单一型和循环型 单一型 ...
随机推荐
- (原创)Stanford Machine Learning (by Andrew NG) --- (week 10) Large Scale Machine Learning & Application Example
本栏目来源于Andrew NG老师讲解的Machine Learning课程,主要介绍大规模机器学习以及其应用.包括随机梯度下降法.维批量梯度下降法.梯度下降法的收敛.在线学习.map reduce以 ...
- Ucenter添加新应用
最近手头上有个项目需要用到Ucenter跟Discuz和UcHome整合到一起,使用同步登录.注册,使用同一的用户数据. 以前没用过Ucenter,第一次接触,看过官网的教程感觉不难.于是开始动手,下 ...
- NServiceBus入门:发送一个命令(Introduction to NServiceBus: Sending a command)
原文地址:https://docs.particular.net/tutorials/intro-to-nservicebus/2-sending-a-command/ 侵删. 能够发送和接收mess ...
- __FILE__,__LINE__,FUNCTION__实现代码跟踪调试
转:http://www.cnitblog.com/zouzheng/archive/2007/08/31/32691.aspx 先看下简单的初始代码:注意其编译运行后的结果. root@xuanfe ...
- 定时任务框架-quartz 时间配置
quartz定时任务时间设置: 这些星号由左到右按顺序代表 : * * * * * * * 格式: [秒] [分] [小时] [日] [月] [周] [年] * 表示所有值. 例如:在分的字段上设置 ...
- luci范例
转自:http://www.cnblogs.com/souroot/p/4511760.html LuCI (Lua Configiration Interface) 是OpenWRT 的Web 管理 ...
- PostgreSQL配置文件--QUERY TUNING
5 QUERY TUNING 5.1 Planner Method Configuration. 下列参数控制查询优化器是否使用特定的存取方法.除非对优化器特别了解,一般情况下,使用它们默认值即可. ...
- SQLAlchemy中filter()和filter_by()的区别
1.filter引用列名时,使用“类名.属性名”的方式,比较使用两个等号“==” 2.filter_by引用列名时,使用“属性名”,比较使用一个等号“=” 3.在使用多条件匹配的时候,filter需要 ...
- Foreach控件使用
在SSIS中,Foreach控件可以循环处理选中的文件中的文件,例如sql文件,Excel文件等.下面就介绍一个比较经典的案例,将一个文件夹中包含的多个Excel文件循环导入至数据库中. 第一步:在数 ...
- 吐血整理 Delphi系列书籍 118本(全)
Delphi 教程 系列书籍 网友(老帅)整理 001_<Delhpi6数据库设计思想与实践> 002_<Delphi6应用开发指南> 003_<Delphi6开发人员指 ...
