从终端创建临时Cron作业

时间:2010-11-14 23:04:05

标签: linux bash shell cron crontab

有没有办法从命令行创建临时的一次性cron作业?我想有一个像鸡蛋计时器一样的功能来打开一个终端并做:

notify "time is up" 30

这将在30分钟后运行:

zenity --info --text="time is up"

对我来说似乎很容易创造,但我很难相信没有人创造出类似的东西。在Ubuntu的存储库中搜索时序包并没有显示任何内容。这是在以前完成的吗?

4 个答案:

答案 0 :(得分:9)

使用at命令。

$ at now + 30 minutes
at> zenity --info --text="time is up"
at> ^D     (press CTRL-D)

时间格式非常灵活。以下是一些例子。

$ at 11:45

$ at 0800 Friday

$ at 4pm + 3 days

$ at 9am tomorrow

答案 1 :(得分:4)

如果您知道$DISPLAY将是相同的,则可以执行以下操作:

echo "DISPLAY=$DISPLAY zenity --info --text=\"time is up\"" | at now + 30 minutes

以这种方式提供环境变量将使zenity在运行时可用。

答案 2 :(得分:2)

你可以自己写一个小脚本。

#! /bin/bash
sleep $(($2 * 60))
zenity --info --text="$1"

使其可执行并从命令行运行它:

./notify "Time is up" 30

答案 3 :(得分:0)