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

摘要:
[ root@lizhipenglinux01~]#Crontab-l查看设置的任务计划201129011echo“OK”˃/root/cron。日志[root@lizhipenglinux01~]#Crontab-r删除任务计划并谨慎使用。[ root@lizhipenglinux01~]#Crontab noocrontabforroot清除/var/log/slow。日志文件201***echo“”˃/var/log/slow。每天早上1:20登录/bin/sh/usr/local/sbin/backup。每个星期天下午3点。03**0/bin/sh/usr/local/sbin/backup。sh每月14日4:10执行/bin/sh/usr/local/sbin/backup_ month。第10414**、bin/sh/usr/local/sbin/backup_月。sh执行ntupdatetime.windows。com.**/8***ntupdatetime.windows。com每8小时的每天1:00、12:00和18:00/bin/sh/usr/local/sbin/test.sh.01,12,18**/bin/sh/usr/local/sbin/test。sh每天9:00至18:00执行/bin/sh/usr/local/sbin/test2.sh。09-18***/bin/sh/usr/local/sbin/test2.sh检查crond服务是否已启动。检查激活。如果已启动,则状态显示为活动。如果未启动,状态显示为不活动。[ root@lizhipenglinux01~]#ls/etc/init。d/functionsnetconsolenetworkREADME[root@lizhipenglinux01~]#Chkconfignetworkoff关闭网络[root@lizhipenglinux01~]#Chkconfig--list注意:此输出仅显示SysV服务,而不显示本机systemd服务。要查看为特定目标启用的服务,请执行“systemctllist dependencies[目标]”。SysV配置数据可能会被本地systemd配置覆盖。

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

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

[root@lizhipenglinux01 ~]# 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文件(如果用户是root,则打开的是/var/spool/cron/root)。打开这个文件使用了vim编辑器,保存时命令模式下输入:wq即可。

[root@lizhipenglinux01 ~]# crontab -l         查看已经设定的任务计划
20 11 29 01 1 echo "OK" > /root/cron.log

[root@lizhipenglinux01 ~]# crontab -r    删除任务计划,慎用。它会一下子把全部计划都删除。如果只想删除一条计划,可以使用-e选项进入crontab进行编辑。
[root@lizhipenglinux01 ~]# crontab -l
no crontab for root

(1)每天凌晨1点20分清除/var/log/slow.log这个文件

20 1 * * * echo "" > /var/log/slow.log

(2)每周日3点执行/bin/sh     /usr/local/sbin/backup.sh。

0 3 * * 0 /bin/sh    /usr/local/sbin/backup.sh

(3)每月14日4点10分执行/bin/sh   /usr/local/sbin/backup_month.sh。

10 4 14 * * 、bin/sh      /usr/local/sbin/backup_month.sh

(4)每隔8小时执行ntpdate time.windows.com

* */8 * * * ntpdate   time.windows.com

(5)每天1点、12点、18点执行/bin/sh    /usr/local/sbin/test.sh。

0 1,12,18 * * * /bin/sh     /usr/local/sbin/test.sh

(6)每天的9点到18点执行/bin/sh   /usr/local/sbin/test2.sh。

0 9-18 * * * /bin/sh   /usr/local/sbin/test2.sh

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

查看一下crond服务是否已经启动,看Active,如果是启动状态显示为active(runing),未启动则显示inacvtive(dead)。

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

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

[root@lizhipenglinux01 ~]# ls /etc/init.d/
functions netconsole network README

[root@lizhipenglinux01 ~]# chkconfig network off       关闭network
[root@lizhipenglinux01 ~]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。

netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:关 3:关 4:关 5:关 6:关

[root@lizhipenglinux01 ~]# chkconfig network on
[root@lizhipenglinux01 ~]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。

netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关

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

[root@lizhipenglinux01 ~]# chkconfig --level 345 network on
[root@lizhipenglinux01 ~]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。

netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关

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

[root@lizhipenglinux01 init.d]# chkconfig --del 123
[root@lizhipenglinux01 init.d]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'。

netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关

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

[root@lizhipenglinux01 init.d]# systemctl enable crond.service
[root@lizhipenglinux01 init.d]# systemctl disable crond
rm '/etc/systemd/system/multi-user.target.wants/crond.service'
[root@lizhipenglinux01 init.d]# systemctl enable crond.service
ln -s '/usr/lib/systemd/system/crond.service' '/etc/systemd/system/multi-user.target.wants/crond.service'
[root@lizhipenglinux01 init.d]# systemctl status crond.service
crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)
Active: active (running) since 日 2018-01-28 18:18:32 CST; 2h 48min ago
Main PID: 861 (crond)
CGroup: /system.slice/crond.service
└─861 /usr/sbin/crond -n

1月 28 18:18:32 lizhipenglinux01 systemd[1]: Started Command Scheduler.
1月 28 18:18:32 lizhipenglinux01 crond[861]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 34% if used.)
1月 28 18:18:32 lizhipenglinux01 crond[861]: (CRON) INFO (running with inotify support)
1月 28 19:07:55 lizhipenglinux01 systemd[1]: Started Command Scheduler.

[root@lizhipenglinux01 init.d]# systemctl disable crond
rm '/etc/systemd/system/multi-user.target.wants/crond.service'

[root@lizhipenglinux01 init.d]# systemctl is-enabled crond
disabled

[root@lizhipenglinux01 init.d]# systemctl enable crond
ln -s '/usr/lib/systemd/system/crond.service' '/etc/systemd/system/multi-user.target.wants/crond.service'

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

软链接

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

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

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

[root@lizhipenglinux01 system]# systemctl list-units -all --state=inactive  列出所有状态inactive的units

[root@lizhipenglinux01 system]# systemctl list-units -all --type=service

[root@lizhipenglinux01 system]# systemctl is-active crond.service
active

[root@lizhipenglinux01 system]# systemctl is-enabled crond.service
enabled

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

[root@lizhipenglinux01 system]# systemctl list-unit-files --type=target  列出系统里所有的target

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

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

[root@lizhipenglinux01 system]# systemctl get-default
multi-user.target

[root@lizhipenglinux01 system]# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

[root@lizhipenglinux01 system]# cat /usr/lib/systemd/system/crond.service
[Unit]
Description=Command Scheduler
After=auditd.service systemd-user-sessions.service time-sync.target

[Service]
EnvironmentFile=/etc/sysconfig/crond
ExecStart=/usr/sbin/crond -n $CRONDARGS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
WantedBy=multi-user.target

免责声明:文章转载自《linux任务计划cron chkconfig工具 systemd管理服务 unit介绍 target介绍》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Golang反射上篇Appium之解锁九宫格下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux下zookeeper的安装教程

zookeeper有单机、伪集群、集群三种部署方式,可根据自己对可靠性的需求选择合适的部署方式。下边对这三种部署方式逐一进行讲解。 注意安装之前必须确认主机已安装jdk,zookeeper的运行依赖java运行环境。 单机: 下载链接:http://archive.apache.org/dist/zookeeper/ 1、 准备好zookeeper安装包,...

Linux中三种SCSI target的介绍之SCST

  版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本文链接:https://blog.csdn.net/scaleqiao/article/details/46753209 1. 简介Linux通用的SCSI 目标子系统(SCST)是一个为Linux SCSI目标子系统的另一种实现。它...

Linux基础(Ubuntu16.04):安装vim及配置

1.进入终端  Ctrl + Alt +T 出现终端窗口 2.输入命令: sudo apt-get install vim-gtk 3.验证是否成功   安装完vim后查看命令 vi tab键,就会关联出所有vi开头的命令,看是否有vim,有则成功. 4.美化vim   输入命令:sudo vim /etc/vim/vimrc   注意: 必须加上sudo...

Linux非Root权限配置Java环境变量

编辑配置文件vi ~/.bashrc设置环境变量 set java environment JAVA_HOME=/home/zoms/java-se-8u41-ri JRE_HOME=/home/zoms/java-se-8u41-ri/jre CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/too...

Linux动态频率调节系统CPUFreq之三:governor

在上一篇文章中,介绍了cpufreq的core层,core提供了cpufreq系统的初始化,公共数据结构的建立以及对cpufreq中其它子部件提供注册功能。core的最核心功能是对policy的管理,一个policy通过cpufreq_policy结构中的governor字段,和某个governor相关联,本章的内容正是要对governor进行讨论。 通过...

解决Ubuntu的root账号无法登录SSH问题-Permission denied, please try again.

刚安装了Ubuntu 14.04 server的虚拟机,普通帐号可以远程登录,但是root不行,输入密码后一直报错: permission denied 最后发现ssh的配置(/etc/ssh/sshd_config)不大一样,14.04的默认配置是: PermitRootLogin without-password 改为: PermitRootLogin...