Linux 上常见的例行性工作

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

1.atd 启动与 at 运作的方式 [root@localhost ~]# /etc/init.d/atd restartStopping atd: [ OK ]Starting atd: [ OK ]2. 设置一下开机启动这个服务[root@localhost ~]# chkconfig atd on3.实际运行单一工作调度《1》再过5分钟后,,将/root/.basrc 寄给root自己[root@localhost ~]# at now +5 minutesat> /bin/mail root -s “testing at job” < /root/.bashrcat> <EOT> 这里输入 ctrl +d 就会出现<EOT> 的字样.job 7 at 2012-09-24 19:50[root@localhost ~]# atq 查询目前主机上面有多少的at工件调度 如果关闭 atrm +工作号6 2012-09-25 23:00 a root7 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-25at> /bin/syncat> /bin/sync at> /sbin/shutdown -h nowat> <EOT>job 6 at 2012-09-25 23:00事实上,当我们使用at时进入at shell 的环境让用户执行工作命令,你最好使用绝对路径来执行8 .batch : 系统有空时才进行后台任务 ,他会在 CPU 工作负载小亍 0.8 的时候,才运行你所下达的工作任务[root@localhost ~]# batch 23:00 2012-9-25at> sync at> sync at> shutdown -h nowat> <EOT> 这里输入 ctrl +d 就会出现<EOT> 的字样.job 8 at 2012-09-25 23:00[root@localhost ~]# atq6 2012-09-25 23:00 a root8 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 -eno crontab for dg – using an empty onecrontab: installing new crontab(2)将不可以使用 crontab 的账号写入其中,若未记录到这个档案当中的使用者,可以使用/etc/cron.deny /etc/cron.deny 比如我在里面加入 dg1[root@localhost ~]# useradd dg1[dg1@localhost ~]$ crontab -eYou (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″</home/dmtsai/.bashrc分时 日月周 命令串[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/crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# 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《–每月

与其临渊羡鱼,不如退而结网。

Linux 上常见的例行性工作

相关文章:

你感兴趣的文章:

标签云: