zoukankan      html  css  js  c++  java
  • linux 通过at命令创建任务

    以Ubuntu为例演示at命令的使用

    /home/fnngj/test/目录下创建file.py 文件

    #!/usr/bin/python
    #coding=utf-8
    f=open('f.txt','w')
    f.write('hello world!!')
    f.close()


    以写('w')操作打开当前目录下的f.txt 文件(没有此文件会自动创建),向文件中写入‘hello world!’,
    然后close()关闭文件。
    通过at 执行创建的file.py 程序。


    fnngj@fnngj-VirtualBox:~/test$ at now+5 minutes
    warning: commands will be executed using /bin/sh
    at> python /home/fnngj/test/fiele.py
    at> <EOT> Ctrl+d 保存退出
    job 17 at Wed Jan 8 17:56:00 2014
    now+5 minutes 表示当前时间,5分钟之后执行
    python /home/fnngj/test/fiele.py 要执行的文件,python 命令,文件要完整的路径
    Ctrl+d 保存退出


    查看创建的任务
    fnngj@fnngj-VirtualBox:~/test$ at -l
    18 Wed Jan 8 17:56:00 2014 a fnngj
    fnngj@fnngj-VirtualBox:~/test$ atq
    10 Wed Jan 8 12:57:00 2014 a fnngj
    at -l / atq 两个命令查看at 创建的任务。


    删除已经设置的任务
    fnngj@fnngj-VirtualBox:~/test$ at -l
    10 Wed Jan 8 12:57:00 2014 a fnngj
    fnngj@fnngj-VirtualBox:~/test$ atrm 10
    10 是任务的“编号”,atrm 用于删除已经创建的任务

    http://fnng.cnblogs.com 209
    启动atd 进程
    linux 一般默认会启动atd 进行

    at 命令指定时间的方式
    绝对计时方法:
    midnight noon teatime
    hh:mm [today]
    hh:mm tomorrow
    hh:mm 星期
    hh:mm MM/DD/YY
    相对计时方法:
    now+n minutes
    mow+n hours
    now+n days
    用法:
    指定在今天下午17:30执行某命令(假设现在时间是下午14:30,2014年1月11日)
    命令格式:
    at 5:30pm
    at 17:30
    at 17:20 today
    at now+3 hours
    at now+180 minutes
    at 17:30 14.1.11
    at 17:30 1.11.14
    博客园---虫师
    http://fnng.cnblogs.com 210
    查看f.txt 文件内容
    fnngj@fnngj-VirtualBox:~/test$ ls
    f.txt~ f.txt open.py open.py~
    fnngj@fnngj-VirtualBox:~/test$ cat f.txt
    hello world!!

  • 相关阅读:
    JAVAWE第一天
    01--2048实例开篇
    10--动作系统(四)动作类中的reverse方法
    09--动作系统(三)使用持续动作
    08--动作系统(二)使用即时动作
    【转】cocos2d-x windows开发环境配置
    07--动作系统(一)
    06--触摸事件响应
    05--简单场景切换与精灵创建
    04--简单菜单使用
  • 原文地址:https://www.cnblogs.com/bokeyuan228/p/7115026.html
Copyright © 2011-2022 走看看