任务计划1

at.allow :优先级高,有此文件,deny无效,只有此文件中的用户可使用at

at.deny:优先级低,此文件中的用户拒绝,不在此文件允许

如果都没有,全都拒绝普通用户

 

 

[root@localhost ~]# rpm -q  at

at-3.1.13-22.el7.x86_64

[root@localhost ~]# rpm -ql  at  // 查找软件包是否存在

 

/usr/lib/systemd/system/atd.service   //  查到以服务形式提供

 

 

[root@localhost ~]# systemctl is-enabled
atd       // centos7  
查看开机是否为启动状态

 

[root@localhost ~]# systemctl status
atd           //  centos7 
查看目前是否已经启动

[root@localhost ~]# systemctl start atd

 

 

[root@localhost ~]# rpm -ql at              //  centos6

/etc/rc.d/init.d/atd

 

 

[root@localhost ~]# chkconfig  –list atd           //     centos6 中查看开机时at服务有没有启动

[root@localhost ~]# runlevel

N 5

 

 

[root@localhost ~]# service atd status             //       查看目前atd服务有没有启动

atd (pid 
1996) is running…

 

 

 

[root@localhost ~]# at  22:52

at> echo fsy

at> touch /app/fsy.txt

at> <EOT>

job 3 at 2017-05-03 22:52

 

 

[root@localhost ~]# ls /app

fsy.txt 
lost+found

You have mail in /var/spool/mail/root

 

 

 

[root@localhost ~]# at -l               //    查看没有执行的计划任务

 

 

[root@localhost ~]# rpm -ql at

/var/spool/at

 

[root@localhost ~]# ll /var/spool/at

 

 

 

 

[root@localhost ~]# su – fsy

 

 

[fsy@localhost ~]$ at 21:07

at> echo fsy

at> touch fsy.txt

at> <EOT>

job 4 at Mon May  8 21:07:00 2017

 

 

[fsy@localhost ~]$ ll /var/spool/at                         //  普通用户无权限访问

ls: cannot open directory /var/spool/at:
Permission denied

 

 

[fsy@localhost ~]$ at -l                                //  查询任务计划

5       Mon
May  8 21:13:00 2017 a fsy

[fsy@localhost ~]$ atrm 5                                 //  删除任务计划

[fsy@localhost ~]$ at -l

 

 

[fsy@localhost ~]$ echo echo fsy > atjob

[fsy@localhost ~]$ at 21:16 < atjob

job 6 at Mon May  8 21:16:00 2017

 

 

[root@localhost ~]# ll /var/spool/at           // 计划任务

total 4

-rwx——. 1 root   root  
2828 May  8 20:58 a00001017c06b8

drwx——. 2 daemon daemon    6 May 
8 21:16 spool

 

 

 

[root@localhost ~]# at -l                       //  查看细节

1       Tue
May  9 18:00:00 2017 a root

[root@localhost ~]# at -c 1

 

 

 

[root@localhost ~]# at -f atjob   17:00            //  直接调用文件atjob

 

[root@localhost ~]# cat atjob| at
18:23            // 
利用管道也可以

 

 

[root@localhost ~]# cat atjob| at 18:23

 

 

 

 

[root@localhost ~]# at -m 21:45                //  任务执行后发个邮件

at> touch at.txt

at> <EOT>

job 9 at Mon May  8 21:45:00 2017

 

 

 

[root@localhost ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

“/var/spool/mail/root”: 3
messages 3 new

>N 
1 fsy                   Mon
May  8 21:07  14/498  
“Output from your job       
4”

 N  2
fsy                   Mon May  8 21:16 
14/498   “Output from your
job        6”

 N  3
root                  Mon May  8 21:45 
13/495   “Output from your
job        9”

 

 

 

[root@localhost ~]# at now+10minutes

at> echo fsy

at> <EOT>

job 11 at Mon May  8 22:00:00 2017

 

 

 

[root@localhost ~]# vim /etc/at.deny

[root@localhost ~]# cat /etc/at.deny

fsy

 

[fsy@localhost ~]$ at 21:59

You do not have permission to use at.

 

 

 

at.allow :优先级高,有此文件,deny无效,只有此文件中的用户可使用at

at.deny:优先级低,此文件中的用户拒绝,不在此文件允许

如果都没有,全都拒绝普通用户

 

49 分钟后 cron

 

 

 

[fsy@localhost ~]$ systemctl status
crond                        //  centos7

crond.service –
Command Scheduler

  
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor
preset: enabled)

  
Active: active (running) since Wed 2017-05-03 21:48:41 CST; 5 days ago

 Main
PID: 1087 (crond)

  
CGroup: /system.slice/crond.service

           └─1087 /usr/sbin/crond
-n

 

 

[root@localhost ~]# service crond status

crond (pid 
1981) is running…

 

 

 

[root@localhost ~]# rpm -ql  cronie

 

[fsy@localhost ~]$ rpm -ql crontabs

 

/etc/crontab                              //   这个文件最重要,定义了系统的计划任务

 

 

 

[root@localhost ~]# cp -a  /etc/ 
/app/etcbak-`date +%F`/                         // 
备份etc目录

[root@localhost ~]# ll /app

total 12

drwxr-xr-x. 138 root root 8192 May  8 21:55 etcbak-2017-05-08

 

 

 

 

 

 

[root@localhost ~]# vim /etc/crontab

任务计划1

 

 

[root@localhost
~]# ll /app/cron.log                    // 
计划任务创建了cron.log

 

 

-rw-r–r–. 1 root
root 0 May  8 23:27 /app/cron.log

 

[root@localhost ~]# ls /var/spool/cron/                 //  存放的是普通用户的计划任务

 

[root@localhost ~]# which touch

/bin/touch

 

[root@localhost ~]# which cp

alias cp=’cp -i’

         /bin/cp

 

 

[root@localhost ~]# vim /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

# | 
|  |  |  |

 * 
*  *  *  *
root  cp /etc/  /app/etcbak2-`date +%F`

 

 

 

 

[root@localhost app]# ll /app/            // 发现没有执行成功,因为/etc/crontab文件中不能有%这样的特殊符号

 

 

 

[root@localhost bin]# pwd

/root/bin

[root@localhost bin]# touch cron.sh

[root@localhost bin]# vim cron.sh

You have new mail in /var/spool/mail/root

[root@localhost bin]# cat cron.sh

#/bin/bash

cp -a /etc /app/etcbak2-`date +%s`

[root@localhost bin]# chmod +x cron.sh

 

[root@localhost bin]# cat  /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/root/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

# | 
|  |  |  |

 * 
*  *  *  *
root cron.sh

 

[root@localhost bin]# echo wall >>
cron.sh             // 
再补一个广播

 

[root@localhost bin]#

Broadcast message from
root@localhost.localdomain (Mon May  8
23:51:02 2017):

 

 

[root@localhost bin]# ll
/app/etcbak2-1494258

ls: cannot access /app/etcbak2-1494258: No such file
or directory  

原创文章,作者:fsy,如若转载,请注明出处:http://www.178linux.com/75857

(0)
fsyfsy
上一篇 2017-05-15 21:30
下一篇 2017-05-15 21:36

相关推荐

  • Shell脚本编程之入门基础(二)if、case的使用

    Shell编程之条件选择和条件判断   一、条件选择(if)与条件判断(case)的对比: if语句:是选择执行,if语句可嵌套。 if条件选择使用格式 单分支 双分支 多分支 if 判断条件;then 条件为真的分支代码 fi if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi if CONDITION1; the…

    Linux干货 2016-08-15
  • linux上的组管理

    上一次我们谈了CentOS上的用户管理,现在我们再来谈下CentOS上的用户组管理。 groupadd创建一个新的组 用法如下: groupadd [选项] groupname 常用选项: -f 强制添加一个组(这个组可能已经存在系统中) -g 指定组的id; -r 创建系统工作组(系统工作组的组ID小于500) -K 覆盖配置文件/ect/log…

    Linux干货 2017-04-09
  • 查找find命令简介

       之前都是写一些关于课后练习题的博客,既练习了课后习题也把博客写了,舒服!不过这周学的知识需要练习的不多,更多的是需要了解和记忆,所以给大家介绍一个自我觉得挺强大的一个命令,那就是查找find命令。大家都知道计算机的数据茫茫多,要想找到自己想要的级必须加点限制性的条件来缩小一下范围,或者准确的告诉计算机你想要的是什么。那么怎么来实现呢…

    2017-08-12
  • 0804正则表达式作业

    用正则表达式表示IP地址         首先来分析一下,制IP地址是一个32位的二进制数,通常被分割为4个“8位二进制数”(也就是4个字节)。IP地址通常用“点分十进制”表示成(a.b.c.d)的形式,其中,a,b,c,d都是0~255之间的十进制整数。例:点分十进IP地址(1…

    Linux干货 2016-08-10
  • 文本处理相关工具

    文本工具       操作系统中,文本的处理这一操作,比如操作一些内容,查看一些内容等等这些东西在linux中都得借助工具来完成对文本的操作。下面来说说对文本处理的工具;  其中:        查看文件内容工具:more、less、cat     &nbsp…

    Linux干货 2016-08-05
  • shell中$(( ))、$( )、“与${ }的区别

    shell中$(( ))、$( )、“与${ }的区别,包括其简单用法。

    2017-09-11