代码之家  ›  专栏  ›  技术社区  ›  Cerin

从终端创建临时Cron作业

  •  3
  • Cerin  · 技术社区  · 14 年前

    有没有办法从命令行创建临时的一次性cron作业?我想有一个类似鸡蛋计时器的功能来打开一个终端,然后:

    notify "time is up" 30
    

    只需在30分钟后运行:

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

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

    4 回复  |  直到 14 年前
        1
  •  4
  •   Dennis Williamson    14 年前

    如果你知道 $DISPLAY 同样,你可以:

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

    以这种方式提供环境变量将使 zenity 当它运行时。

        2
  •  9
  •   Barry Brown    14 年前

    使用 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
    
        3
  •  2
  •   Barry Brown    14 年前

    你可以给自己写个小剧本。

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

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

    ./notify "Time is up" 30
    
        4
  •  0
  •   user229044    14 年前