Linux下如何在特定时间执行特定任务


Linux下如何在特定时间执行特定任务

1 仅执行一次的任务
2 循环执行的任务
3 可唤醒停机期间的工作任务

1 仅执行一次的任务
所需程序
atd服务
at命令
启动atd # service atd restart
atd stop/waiting
atd start/running, process 11031
千万注意要在root下执行,不然会提示Rejected send message.

at的使用
使用at的权限(因为安全性考虑最好设置)
在/etc/at.allow中设置可以使用at的账号
在/etc/at.deny中设置不可以使用at的账号
示例
1分钟后执行mkdir $ at now + 1 minutes
warning: commands will be executed using /bin/sh
at> mkdir helloAt
at> <EOT>
job 1 at Wed Feb  6 14:36:00 2013
查看工作 # at -c 2
#!/bin/sh
# atrun uid=0 gid=0
# ...
$ mkdir helloAt
特定时间关机 $ at 14:00 2013-2-9
warning: commands will be executed using /bin/sh
at> /bin/sync
at> /bin/sync
at> /sbin/shutdown -h now
at> <EOT>
job 4 at Sat Feb  9 14:00:00 2013
at如何执行
输入输出:标准输入输出会重定向到mailbox里,所以执行echo "hello"在终端下是看不到的
后台工作:系统会将at工作独立于shell,交给atd程序接管,即使关了shell也没关系
查询与删除at中的工作
查询:atq
删除:atrm jobid
batch:和at相似,只是在cpu负载低时才执行

  • 1
  • 2
  • 下一页

相关内容