任务计划、chkconfig工具、systemd管理服务、unit、target

比如备份数据或者重启服务。

crontab -u、-e、-l、-r(删除)

格式:分 时 日 月 周 user command

文件/var/spool/cron/username

分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7

可用格式1-5表示一个范围1到5

可用格式1,2,3表示1或者2或者3

可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时

要保证服务是启动状态

systemctl start crond.service

cat /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# 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

crontab –e  //进入编辑模式

0 2 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.txt 2>>12.txt

#每天凌晨2点 执行脚本123.sh 把正确的输入到123.txt,把错误的输入到12.txt

0 2 1-4 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.txt 2>>12.txt

#每天凌晨2点,1到4号,2,4,6,8,10,12月(能被2整除的)周2和周5,一个区间用-。和逗号隔开  执行脚本 123.sh 把正确的输入到123.txt,把错误的输入到12.txt

任务计划没执行

1.可能脚本里可能只是一个命令,不是绝对路径 //(因为不在crond的PATH里。cat /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin)。最好的办法就是写绝对路径

2.追加一个日志,正确的输出或者错误的输出。保证有据可查

chkconfig服务管理工具

chkconfig --list  //查看系统使用chkcongfig服务有哪些

chkconfig network on/off  //分别表示开机开机还是关闭

chkconfig --level 3 network off  //关闭3级别

chkconfig --level 345 network off  //关闭345级别

chkconfig --del network //删除

chkconfig --add network  //增加

chkconfig --he

自己添加一个服务

要把文件放到/etc/init.d目录下

systemd服务管理

systemctl list-units --all --type=service //所有的服务都列出(包括未激活的)几个常用的服务相关的命令

systemctl enable crond.service //让服务开机启动

systemctl disable crond //不让开机启动

systemctl status crond //查看状态

systemctl stop crond //停止服务

systemctl start crond //启动服务

systemctl restart crond //重启服务

systemctl is-enabled crond //检查服务是否开机启动

unit介绍

ls /usr/lib/systemd/system //系统所有unit,分为以下类型

service 系统服务

target 多个unit组成的组

ls -l runlevel*

device 硬件设备

mount 文件系统挂载点

automount 自动挂载点

path 文件或路径

scope 不是由systemd启动的外部进程

slice 进程组

snapshot systemd快照

socket 进程间通信套接字

swap  swap文件

timer 定时器

unit相关的命令

systemctl list-units //列出正在运行的unit

systemctl list-units --all //列出所有,包括失败的或者inactive的

systemctl list-units --all --state=inactive //列出inactive的unit

systemctl list-units --type=service//列出状态为active的service

systemctl is-active crond.service //查看某个服务是否为active

target介绍

系统为了方便管理用target来管理unit

systemctl list-unit-files --type=target //列出所有的target

systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit

systemctl get-default //查看系统默认的target

systemctl set-default multi-user.target

一个service属于一种类型的unit

多个unit组成了一个target

一个target里面包含了多个service

cat /usr/lib/systemd/system/sshd.service //看这个service属于哪个unit。看[install]部分

时间: 2024-07-30 19:57:47

任务计划、chkconfig工具、systemd管理服务、unit、target的相关文章

linux任务计划cron chkconfig工具 systemd管理服务 unit介绍 target介绍

[[email protected] ~]# crontab -e  编写任务计划no crontab for root - using an empty one 20 11 29 01 1 echo "OK" > /root/cron.log      表示在1月29日(星期一)的11点20分执行:echo  "OK" > /root/cron.log 命令crontab -e 实际上打开/var/spool/cron/username文件(如果用户是

任务计划cron / chkconfig工具/ system管理服务/unit及target介绍

一.linux任务计划cron 1.cat /etc/crontab 任务计划的配制文件: 2.crontab -e 编辑配制文件. 图片说明,每个月的1-10号3点执行脚本123.sh ,以追加形式生成日志文件123.log,生成错误文件日志321.log crontab -e 实际上是打开了 "/var/spool/cron/username" (如果是root则打开的是/var/spool/cron/root)这个文件,所以不要直接去编辑那个文件,因为可能会出错,所以一定要使用

linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、target介绍

linux任务计划cron [[email protected] ~]# crontab -e no crontab for root - using an empty one 每天的凌晨3点 执行这个 0 3 * * * /usr/bin/touch /root/123.txt &>/dev/null 启动服务 [[email protected] ~]# systemctl start crond 基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟

cron计划任务、chkconfig工具、systemd管理服务、unit、target介绍

1. linux任务计划cron linux的大部分系统管理工作都是通过定期自动执行某个脚本来完成的,那么如何定期执行某个脚本呢?这就要借助linux的cron功能了,这部分的内容很重要,请牢记! 命令crontab linux的任务计划功能的操作都是通过crontab命令来完成的,其常用的选项有以下几个: -u:表示指定某个用户,不加-u选项则为当前用户. -e:表示制定计划任务 -l:表示列出计划任务 -r:表示删除计划任务 任务计划的配置文件: # cat /etc/crontab SHE

linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe

一. linux任务计划cron 关于cron任务计划功能的操作都是通过crontab这个命令来完成的. 其中常用的选项有: -u :指定某个用户,不加-u选项则为当前用户: /etc/crontab 任务计划的配置文件 前面两行是定义变量,第三行是指发送邮件给谁,然后最后一行有五个点分别对应着五个位,也就是上面的五行,分别表示:1.表示分钟(0-59)2.表示小时(0-23)3.表示日期(1-31)4.表示月份(1-12可以写数字或者英文的简写)5.表示星期(0-6,0或者7表示周日,也可以写

十(6)任务计划 cron、chkconfig工具、systemd管理服务、unit、target

                  Linux 任务计划 cron 任务计划的配置文件: /etc/crontab (图中:MAILTO 表示发送任务计划给谁) crontab: -u:表示指定某个用户,不加-u则为当前用户 -e :表示制定计划任务(进入到编辑模式) -l :列出计划任务 -r: 删除计划任务 进入编辑模式 : crontab -e (编写任务计划crond服务是如果执行一个bash/命令,写它的绝对路径) 指定执行范围:   ( 分范围0-59,时范围0-23,日范围1-31

三十四、Linux系统任务计划cron、chkconfig工具、systemd管理服务、unit介绍

三十四.Linux系统任务计划cron.chkconfig工具.systemd管理服务.unit介绍.target介绍 一.Linux系统任务计划cron crontab命令:对任务计划功能的操作用此命令.选项: -u:指定某个用户,不加-u则为当前用户. -e:制定任务计划. -l:列出任务计划. -r:删除任务计划. 任务计划的配置文件:/etc/crontab 文件内共有五个字段. 从左往右依次为:分.时.日.月.周.用户.命令. 可以不指定用户就是root. # crontab -e  

Linux centos7 linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、 target介绍

一.linux任务计划cron crontab -u  -e -l -r 格式;分 时 日 月 周 user command 文件/var/spool/corn/username 分范围0-59,时范围0-23,日范围0-31,月范围0-12,周1-6 可用格式1-5表示一个范围1到5 可用格式1,2,3表示1或2或3 可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时 启动 systemctl etop crond停止 systemctl start crond.service  二

10.23 linux任务计划cron10.24chkconfig工具10.25 systemd管理服务10.26 unit介绍 10.27 target介绍

- 10.23 linux任务计划cron - 10.24 chkconfig工具 - 10.25 systemd管理服务 - 10.26 unit介绍 - 10.27 target介绍 - 扩展 1. anacron http://blog.csdn.net/strikers1982/article/details/4787226  2. xinetd服(默认机器没有安装这个服务,需要yum install xinetd安装) http://blog.sina.com.cn/s/blog_46

八周1课 任务计划cron,chkconfig工具,systemd管理服务,unit,target

linux任务计划在linux中,任务计划是必不可少的,在linux中怎样设置任务计划呢?首先看一个文件[[email protected] ~]# cat /etc/crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root For details see man 4 crontabs Example of job definition: .---------------- minute (0 - 59)(时间的分钟)