zoukankan      html  css  js  c++  java
  • Ubuntu 14.04 定时任务

    如何在Ubuntu上启动一个定时任务,使得可以定时删除机器上的日志

    首先,

    #查看cron状态
    service cron status
     
    如果提示没有安装
    #安装cron服务
    apt-get install cron
     
    如果提示正在运行
    #编辑当前用户的计划任务文件
    crontab -e 
     
    弹出编辑界面,如下文件,加入最后一行代码,意思是每两分钟向/home/cron_test文件写入一次Hello World
    # Edit this file to introduce tasks to be run by cron. 
    # 
    # Each task to run has to be defined through a single line
    # indicating with different fields when the task will be run
    # and what command to run for the task
    # 
    # To define the time you can provide concrete values for
    # minute (m), hour (h), day of month (dom), month (mon),
    # and day of week (dow) or use '*' in these fields (for 'any').# 
    # Notice that tasks will be started based on the cron's system
    # daemon's notion of time and timezones.
    # 
    # Output of the crontab jobs (including errors) is sent through
    # email to the user the crontab file belongs to (unless redirected).
    # 
    # For example, you can run a backup of all your user accounts
    # at 5 a.m every week with:
    # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
    # 
    # For more information see the manual pages of crontab(5) and cron(8)
    # 
    # m h dom mon dow command
    */2 * * * * echo "Hello World" >> /home/cron_test 
    

      

    CTRL+x 退出,此时提示是否保存,输入yes,然后回车

    #重载cron
    sudo service cron reload
     
    #显示当前用户的计划任务文件
    crontab -l 
    此时会弹出当前用户的计划任务的文件内容
     
    #重启cron服务
    sudo service cron restart
     
    然后tail -f /home/cron_test,将会每两分钟显示一次Hello World
     
    结束~~
  • 相关阅读:
    A journey on the Android Main Thread
    android的消息处理机制(图+源码分析)——Looper,Handler,Message
    用fragment创建一个选项卡
    fragment的生命周期
    动态创建fragment
    自定义自动换行布局
    Android开源框架Universal-Image-Loader完全解析(三)
    第七章 摄影技术
    第六章 镜头的成像像质评价
    第五章 镜头像差的成因,校正及规避方法
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9780928.html
Copyright © 2011-2022 走看看