Linux 计划任务crontab详解,含笔试题讲解

本文详细介绍了Linux系统中的计划任务工具crontab,包括创建、查看和管理计划任务的方法,以及一些常见笔试题的解答。内容涉及crontab的使用、计划任务的存放位置、进程检查、脚本编写、用户权限和日志监控等方面,旨在帮助读者理解和掌握crontab的使用技巧。
摘要由CSDN通过智能技术生成

计划任务(crontab)

计划任务不是必须要的,但是它有很大的作用

优势:解放人力,提升效率,自动化

定时定点去执行脚本(程序)

crontab -e:创建计划任务 -e edit

crontab -l:查看计划任务 -l list

[root@master 417]# crontab -e  #创建计划任务的命令   -e  编辑  edit

30 3 * * *  bash  /lianxi/417/backup_log.sh    每天凌晨3:30执行脚本backup_log.sh
[root@master 417]# crontab  -l  #查看计划任务  list
30 3 * * *  bash  /lianxi/417/backup_log.sh

#示例
# 20 8 23 7 *  bash  /lianxi/417/backup_log.sh  
# 7月23日的早上8点20 执行脚本

# /  间隔的时间频率,间隔多久
# ,  单个的,多个不连续的时间点
# -  连续的时间范围
# */1 * * * *   每分钟去执行
# */5 * * * *   每5分钟去执行
# 30 8 3,8,10 * *   每月的3号,8号,10号的8点30执行
# 30 8 8-18 * *     每月的8号到18号的8点30执行
# 30 8-18 * * *     每天的8点30 9点30 ....  18点30执行

查看计划任务格式

# 默认只能精确到分钟,最短时间间隔是1分钟
[root@master 417]# 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

停止、启动、重启crond服务

#停止crond服务:
[root@localhost lianxi]# service crond stop
Redirecting to /bin/systemctl stop crond.service --》 centos8里面真正执行的命令

#开启crond服务:
[root@localhost lianxi]# service crond start
Redirecting to /bin/systemctl start crond.service --》 centos8里面真正执行的命令

#重启crond服务:
[root@localhost lianxi]# service crond restart
Redirecting to /bin/systemctl restart crond.service --》 centos8里面真正执行的命令

笔试题

1.计划任务存放在哪里?

/var/spool/cron/ --》存放计划任务的目录

2.任何一个用户是否都可以创建计划任务

是的,并且每个用户都有一个对应的文件存放这个用户的计划任务

root用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值