1.1 特殊权限u+s /o+t
[[email protected] ~]# ls -ld /bin/ls /usr/bin/passwd /tmp/ /usr/bin/locate
-rwxr-xr-x. 1 root root 117048 Mar 23 2017 /bin/ls
drwxrwxrwt. 3 root root 4096 Jul 25 16:27 /tmp/
-rwx--s--x. 1 root slocate 38464 Mar 12 2015 /usr/bin/locate
-rwsr-xr-x. 1 root root 30768 Nov 24 2015 /usr/bin/passwd #SUID
[[email protected] ~]# ll /bin/ls /bin/touch
-rwxr-xr-x. 1 root root 117048 Mar 23 2017 /bin/ls
-rwxr-xr-x. 1 root root 52560 Mar 23 2017 /bin/touch
[[email protected] ~]# chmod u+s /bin/ls /bin/touch
[[email protected] ~]# ll /bin/ls /bin/touch
-rwsr-xr-x. 1 root root 117048 Mar 23 2017 /bin/ls
-rwsr-xr-x. 1 root root 52560 Mar 23 2017 /bin/touch
[[email protected] ~]# chmod u+s /bin/ls
[[email protected] ~]# ll /bin/ls
-rwsr-xr-x. 1 root root 117048 Mar 23 2017 /bin/ls
[[email protected] ~]# stat /bin/ls
File: `/bin/ls‘
Size: 117048 Blocks: 232 IO Block: 4096 regular file
Device: 803h/2051d Inode: 263579 Links: 1
Access: (4755/-rwsr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-08-06 09:13:37.131651698 +0800
Modify: 2017-03-23 02:52:45.000000000 +0800
Change: 2018-07-25 16:37:29.016952182 +0800
第2章 定时任务(多量)
2.1 定时任务cron
[[email protected] w]#ll -d /etc/cron.*
drwxr-xr-x. 2 root root 4096 Aug 3 05:15 /etc/cron.d
drwxr-xr-x. 2 root root 4096 Jul 13 18:26 /etc/cron.daily
-rw-------. 1 root root 0 Aug 24 2016 /etc/cron.deny
drwxr-xr-x. 2 root root 4096 Jul 13 18:23 /etc/cron.hourly
drwxr-xr-x. 2 root root 4096 Jul 13 18:24 /etc/cron.monthly
drwxr-xr-x. 2 root root 4096 Sep 27 2011 /etc/cron.weekly
[[email protected] w]#
2.2 定时任务cron的命令crontab
[[email protected] ~]# #crontab -l === cat /var/spool/cron/root crontab -l查询相当于是cat
[[email protected] ~]# #crontab -e === vi /var/spool/cron/root crontab -e相当于是vim
[[email protected] w]####crontab –r ==== delet /var/spool/cron/root crontab –r 相当于是删除
-v 列出用户cron作业的状态
[[email protected] ~]# #crontab语法检查功能(定时任务格式)
2.3 检查定时任务是否运行? Crond
[[email protected] w]#ps -ef |grep crond
root 1597 1 0 Aug07 ? 00:00:00 crond
root 4065 3948 0 16:59 pts/3 00:00:00 grep --color cron
2.4 开机是否自启动chkconfig |grep crond
[[email protected] w]#chkconfig |grep crond
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.5 定时任务配置文件格式:
格式:分(minute) 时(hour) 日(day) 月(mouth) 周(week)
2.5.1 什么时候 做什么?
一般用于定时备份文件数据而用
每天的上午8点30分,来学校上车(go to school) 每天晚上12点准时,回家自己开车(go to bed)
2.6 每分钟显示自己的名字追加到/tmp/name.log中
2.6.1 命令
[[email protected] w]#echo wangweigang >>/tmp/name.log
[[email protected] w]#cat /tmp/name.log
oldboy
王维港
wangweigang
2.6.2 #书写定时任务
crontab -e
2.6.3 #检查
##1.检查文件内容
[[email protected] w]#crontab -l
#printf oldboyedu student at 2018.8.08
-
-
-
-
- echo wangweigang >>/tmp/name.log
##2.检查日志
[[email protected] w]#cat /tmp/name.log
oldboy
王维港
wangweigang
wangweigang
[[email protected] w]#
2.7 每2分钟同步下系统时间
2.7.1 命令
[[email protected] w]#ntpdate ntp1.aliyun.com
8 Aug 17:40:28 ntpdate[4141]: adjust time server 120.25.115.20 offset 0.248269 sec
[[email protected] w]#which crond
/usr/sbin/crond
[[email protected] w]#
- echo wangweigang >>/tmp/name.log
-
-
-
2.7.2 写入定时任务
crontab -e
/2 /usr/sbin/crondntpdate ntp1.aliyun.com
2.7.3 检查
[[email protected] w]#crontab -l
#printf oldboyedu student at 2018.8.08
# echo wangweigang >>/tmp/name.log
/2 /usr/sbin/crondntpdate ntp1.aliyun.com
[[email protected] w]#
2.8 案例
每天的上午7点到上午11点 每2小时运行CMD命令
00 07-11/2 TF
00 07,09,11 * TF
2.9 开机自启动
- 23,00-07/1 /application/nginx/sbin/nginx -s reload
00 23,00-07/1 /application/nginx/sbin/nginx -s reload
2.10 自创文件放置脚本
[[email protected] ~]# mkdir -p /server/scripts
[[email protected] w]# cat show.sh
date +%F_%T
You have new mail in /var/spool/mail/root
[[email protected] w]# sh /server/scripts/show.sh
2018-08-08_17:55:26
[[email protected] w]#
原文地址:http://blog.51cto.com/13859027/2156458