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
     
    结束~~
  • 相关阅读:
    Poj 1742 Coins(多重背包)
    Poj 2350 Above Average(精度控制)
    求二进制数中1的个数
    Poj 1659 Distance on Chessboard(国际象棋的走子规则)
    Poj 2411 Mondriaan's Dream(压缩矩阵DP)
    Poj 2136 Vertical Histogram(打印垂直直方图)
    Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)
    poj 2390 Bank Interest(计算本利和)
    Poj 2533 Longest Ordered Subsequence(LIS)
    Poj 1887 Testing the CATCHER(LIS)
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9780928.html
Copyright © 2011-2022 走看看