linux at shell,shell 用at命令来计划执行作业

at命令允许指定Linux系统何时运行脚本。at命令会将作业提交到队列中,指定shell何时运 行该作业。at的守护进程atd会以后台模式运行,检查作业队列来运行作业。大多数Linux发行 版会在启动时运行此守护进程。

atd守护进程会检查系统上的一个特殊目录(通常位于/var/spool/at)来获取用at命令提交的 作业。默认情况下,atd守护进程会每60秒检查一下这个目录。有作业时,atd守护进程会检查作业设置运行的时间。如果时间跟当前时间匹配,atd守护进程就会运行此作业。

当作业在Linux系统上运行时,显示器并不会关联到该作业。取而代之的是,Linux系统会将

提交该作业的用户的电子邮件地址作为STDOUT和STDERR。任何发到STDOUT或STDERR的输出都 会通过邮件系统发送给该用户。

使用e-mail作为at命令的输出极其不便。at命令利用sendmail应用程序来发送邮件。如 果你的系统中没有安装sendmail,那就无法获得任何输出,因此在使用at命令时,最好在脚本 中对STDOUT和STDERR进行重定向.

code

macname@localhost Desktop %cat test.sh

#!/bin/bash

# Testusingat command

#

echo"This script ran at $(date +%B%d,%T)" > test13b.out echo >> test13b.outsleep5echo"This is the script's end..." >> test13b.out% macname@localhost Desktop %macname@localhost Desktop%

#创建at任务

macname@localhost Desktop % at -m -f test.sh now

job1 at Mon Nov 30 22:17:11 2020macname@localhost Desktop%macname@localhost Desktop%

#查看at任务

macname@localhost Desktop %atq1 Mon Nov 30 22:17:00 2020macname@localhost Desktop%

#删除at任务

macname@localhost Desktop % atrm 1macname@localhost Desktop%

添加多个at任务

macname@localhost Desktop % at -m -f test.sh 22:20job2 at Mon Nov 30 22:20:00 2020macname@localhost Desktop%atq2 Mon Nov 30 22:20:00 2020macname@localhost Desktop%macname@localhost Desktop% at -m -f test.sh teatime

job3 at Tue Dec 1 16:00:00 2020macname@localhost Desktop% at -m -f test.sh tomorrow

job4 at Tue Dec 1 22:21:00 2020macname@localhost Desktop%atq3 Tue Dec 1 16:00:00 2020

2 Mon Nov 30 22:20:00 2020

4 Tue Dec 1 22:21:00 2020macname@localhost Desktop%

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值