系统的定时,延时

1.at

at -l      查看任务信息
at -r      删除任务
at -c      查看指定任务信息



[root@foundation42 ~]# at 09:21
at> rm -fr /mnt/file{1..5}
at> <EOT>
job 4 at Sun Apr 22 09:21:00 2018
[root@foundation42 ~]# at now+2min
at> touch westos{1..5}
at> <EOT>
job 5 at Sun Apr 22 09:22:00 2018
[root@foundation42 ~]# at -l
4    Sun Apr 22 09:21:00 2018 a root
5    Sun Apr 22 09:22:00 2018 a root


vim /etc/at.deny  打开at的黑名单文件,系统黑名单默认存在
在黑名单的用户无法执行at命令


vim /etc/at.allow at白名单  系统不默认存在 需自行建立
当白名单出现系统黑名单失效
黑名单
[root@foundation42 ~]# useradd westos
[root@foundation42 ~]# useradd linux      先添加两个用户进行实验
[root@foundation42 ~]# vim /etc/at.deny   在文件中添加westos用户
[root@foundation42 ~]# su - westos    
[westos@foundation42 ~]$ at 09:35
You do not have permission to use at.      at无法执行
[westos@foundation42 ~]$ exit
logout
[root@foundation42 ~]# su - linux
[linux@foundation42 ~]$ at 09:36
at> <EOT>
job 6 at Sun Apr 22 09:36:00 2018    at可执行



白名单
[root@foundation42 ~]# vim /etc/at.allow    建立白名单,添加westos用户,黑名单失效
[root@foundation42 ~]# su - westos   
Last login: Sun Apr 22 09:34:04 CST 2018 on pts/1
[westos@foundation42 ~]$ at 09:44
at> <EOT>
job 7 at Sun Apr 22 09:44:00 2018
[westos@foundation42 ~]$ exit
logout
[root@foundation42 ~]# su - linux
Last login: Sun Apr 22 09:34:22 CST 2018 on pts/1
[linux@foundation42 ~]$ at 09:44

You do not have permission to use at.   linux用户未在白名单内,无法使用at命令

2.crontab

crontab -u root -e 编写命令
crontab -u root -l 查看命令
crontab -u root -r 删除命令


[root@foundation42 ~]# crontab -u root -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@foundation42 ~]# crontab -u root -l
54 09 * * * touch file{1..5}


 

分钟       小时     天      月            周
  *         *      *       *             *
 *          8-17   *       *             *   表示每天的8点到17点
*/2         8-17  1,15     *              *  表示在一号和15号的8-17点之间的每两分钟

查看命令的详细信息

 The time and date fields are:

              field          allowed values
              -----          --------------
              minute         0-59
              hour           0-23
              day of month   1-31
              month          1-12 (or names, see below)
              day of week    0-7 (0 or 7 is Sunday, or use names)

       A  field  may  contain  an  asterisk  (*),  which  always  stands   for
       "first-last".

       Ranges of numbers are allowed.  Ranges are two numbers separated with a
       hyphen.  The specified range is inclusive.  For example, 8-11 for an

       Lists are allowed.  A list is a set of numbers (or ranges) separated by
       commas.  Examples: "1,2,5,9", "0-4,8-12".


Step  values can be used in conjunction with ranges.  Following a range
       with "/<number>" specifies skips of  the  number's  value  through  the
       range.  For example, "0-23/2" can be used in the 'hours' field to spec‐
       ify command execution for every other hour (the alternative in  the  V7
       standard  is  "0,2,4,6,8,10,12,14,16,18,20,22").   Step values are also
       permitted after an asterisk, so if specifying a job to be run every two
       hours, you can use "*/2".

       Names  can  also be used for the 'month' and 'day of week' fields.  Use
       the first three letters of the particular day or month (case  does  not
       matter).  Ranges or lists of names are not allowed.



crontab同样有黑名单和白名单

运行功能与at相同







[root@foundation42 cron]# cd /etc/cron.d
[root@foundation42 cron.d]# ls
0hourly  raid-check  sysstat
[root@foundation42 cron.d]# touch file
[root@foundation42 cron.d]# vim file
[root@foundation42 cron.d]# cat file
* * * * * root touch /mnt/file{1..5}

[root@foundation42 cron.d]# touch rm-file
[root@foundation42 cron.d]# vim rm-file


可以将写好的脚本放在以下目录中,系统会自动运行
cd /etc/c
cron.daily/   每天执行一次
cron.monthly/ 每月执行一次
cron.hourly/  每小时执行一次
cron.weekly/  每周执行一次


处理临时文件

 systemd-tmpfiles --creat /usr/lib/tmpfiles.d/*

vim westos.conf

d /mnt/ 1777 root root 5s

touch /mnt/file

##############################

遇到vnc无法连接的情况处理

 cd /etc/sysconfig/network-scripts/

删除除ifcfg-lo外的ficfg文件

然后执行 work-hostset

reboot


猜你喜欢

转载自blog.csdn.net/a313434458/article/details/80037511