linux 例行性工作,Linux 上常见的例行性工作

一 、仅执行一次的工作调度单一工作排程的运作,那就是 at 这个指令的运作!

1.atd 启动与 at 运作的方式

[root@localhost ~]# /etc/init.d/atd restart

Stopping atd:                                              [ OK ]

Starting atd:                                              [ OK ]

2. 设置一下开机启动这个服务

[root@localhost ~]# chkconfig atd on

3.实际运行单一工作调度

《1》再过5分钟后,将/root/.basrc 寄给root自己

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

at> /bin/mail root -s "testing at job" < /root/.bashrc

at>         ß这里输入    ctrl +d 就会出现 的字样.

job 7 at 2012-09-24 19:50

[root@localhost ~]# atq ß查询目前主机上面有多少的at工件调度 如果关闭 atrm +工作号

6     2012-09-25 23:00 a root

7     2012-09-24 20:05 a root

[root@localhost ~]# at -c 6

#!/bin/sh

# atrun uid=0 gid=0

# mail     root 0

《2》将上述的第5项工作内容列出来查阅

如果 在23:00停电 关机 命令如下

[root@localhost ~]# at 23:00 2012-9-25

at> /bin/sync

at> /bin/sync

at> /sbin/shutdown -h now

at>

job 6 at 2012-09-25 23:00

事实上,当我们使用at时进入at shell 的环境让用户执行工作命令,你最好使用绝对路径来执行

8 .batch : 系统有空时才进行后台任务 ,他会在 CPU 工作负载小亍 0.8 的时候,才运行你所下达的工作任务

[root@localhost ~]# batch 23:00 2012-9-25

at> sync

at> sync

at> shutdown -h now

at>     ß这里输入    ctrl +d 就会出现 的字样.

job 8 at 2012-09-25 23:00

[root@localhost ~]# atq

6   2012-09-25 23:00 a root

8   2012-09-25 23:00 a root

二、循环执行的例行性工作调度

用户想要新建环形工作调度时,使用的是crontab 这个命令。不过,为了安全性的问题,与at类似,我们可以限制使用crontab 的用户账号。使用限制数据有。

1.用户的设置

(1)将可以使用 crontab 的账号写入其中,若不在这个档案内的使用者则不可使用/etc/cron.allow ;

vi /etc/cron.allow  比如我在里面加入 root dg 这两个用户 注:每个用户各占一行

[dg@localhost ~]$ crontab -e

no crontab for dg - using an empty one

crontab: installing new crontab

(2)将不可以使用 crontab 的账号写入其中,若未记录到这个档案当中的使用者,可以使用/etc/cron.deny

/etc/cron.deny   比如我在里面加入 dg1

[root@localhost ~]# useradd dg1

[dg1@localhost ~]$ crontab -e

You (dg1) are not allowed to use this program (crontab)

See crontab(1) for more information

默认情况下只要不被列入/etc/cron.deny 当中就能直接执行crontab -e

(3)进入后输入如下

0 12 * * * mail dmtsai -s "at 12:00"

分时 日月周    命令串

[root@localhost ~]# crontab –l   查询      crontab –r 删除

1 12 * * * mail dmtsai -s "at 12:00"< /home/dmtsai/.bashrc

假如每5分钟需要执行 /home/dmtsai/test.sh

*/5 * * */home/dmtsai/test.sh

系统的配置文件 : /etc/crontab

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

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

# run-parts

分时日月周执行者 命令串

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily 《--每天

22 4 * * 0 root run-parts /etc/cron.weekly 《--每周

42 4 1 * * root run-parts /etc/cron.monthly《--每月0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值