如何在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
 
结束~~

Ubuntu 14.04 定时任务的更多相关文章

  1. Ubuntu 14.04中Elasticsearch集群配置

    Ubuntu 14.04中Elasticsearch集群配置 前言:本文可用于elasticsearch集群搭建参考.细分为elasticsearch.yml配置和系统配置 达到的目的:各台机器配置成 ...

  2. deepsooncms在Ubuntu 14.04上部署教程

    deepsooncms在Ubuntu 14.04上部署教程 一.安装mono1.在命令行运行sudo apt-key adv --keyserver keyserver.ubuntu.com --re ...

  3. Ubuntu 14.04 中 安装elasticsearch2.*+logstash2.*+kibana

    在Ubuntu 14.04 上安装单机版ELK 2.*(脚本化) 1.判断是否为root权限 if [ "${UID}" -ne 0 ]; then echo "You ...

  4. 【DDD/CQRS/微服务架构案例】在Ubuntu 14.04.4 LTS中运行WeText项目的服务端

    在<WeText项目:一个基于.NET实现的DDD.CQRS与微服务架构的演示案例>文章中,我介绍了自己用Visual Studio 2015(C# 6.0 with .NET Frame ...

  5. Ubuntu 14.04 LTS下安装Google Chrome浏览器

    在Ubuntu 14.04下安装Google Chrome浏览器非常简单,只要到Chrome的网站下载Deb安装包并进行安装即可.当然你也可以使用APT软件包管理器来安装Google Chrome浏览 ...

  6. 烂泥:ubuntu 14.04搭建OpenVPN服务器

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 公司分部需要连接公司内部的服务器,但是该服务器只允许公司内部的网络访问. 为了解决这个问题,打算使用VPN.对于VPN以前使用最多的是PPTP这个解决方案 ...

  7. ubuntu 14.04 desktop装vnc4server

    ubuntu 14.04 desktop上安装vnc4server要装上gnome的一些软件包并修改启动文件~/.vnc/xstartup 问题来源How to make VNC Server wor ...

  8. 在Ubuntu 14.04安装和使用Docker

    Docker是一个开源软件,它可以把一个Linux应用和它所依赖的一切(比如配置文件)都封装到一个容器.然而,Docker与虚拟机不同,它使用了沙箱机制,Docker容器不运行操作系统,它共享主机上的 ...

  9. Window7下安装Ubuntu 14.04 64bit

    本文章主要讲解如何在Windows7操作系统中硬盘安装Ubuntu 14.04 64bit: 1.准备文件 1.ubuntu-14.04.4-desktop-amd64.iso 2.EasyBCD.e ...

随机推荐

  1. Oracle多关键字模糊查询

    以前写SQL时,知道MySQL多字段模糊查询可以使用[charlist] 通配符,如: SELECT * FROM Persons WHERE City LIKE '[ALN]%'但是在Oracle中 ...

  2. 尝试.Net Core—使用.Net Core + Entity FrameWork Core构建WebAPI(一)

    想尝试.Net Core很久了,一直没有时间,今天回家,抛开一切,先搭建一个.Net Core的Demo出来玩玩. 废话少说,咱直奔主题: 一.开发环境 VS2015 Update3 Microsof ...

  3. [LeetCode] 867. Transpose Matrix_Easy

    Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it ...

  4. VB.net 与线程

    Imports System.Threading Imports System Public Class Form1 Dim th1, th2 As Thread Public Sub Method1 ...

  5. python 全局变量与局部变量

    一.引用 使用到的全局变量只是作为引用,不在函数中修改它的值的话,不需要加global关键字.如: #! /usr/bin/python a = 1 b = [2, 3] def func(): if ...

  6. cocos代码研究(1)Node学习笔记

    理论部分 Node类继承自Ref类,是cocos框架中基础底层的一个封装类,与画面渲染相关的类一般都是继承自该类,例如Scene,Layer,Sprite,Sprite3D,Label,SpriteB ...

  7. toFixed()与toPrecision()

    toFixed(n): 返回一个字符串,代表一个以定点表示法表示的数字. n在0~20之间 var g=1.023; var f=g.toFixed(2); f的值为:1.02,     typeof ...

  8. 小试---EF5.0入门实例1

    现在做个小练习吧~~~ 第一步:首先新建一个数据库名字为Test;数据库里面只有一个表UserTable 脚本为: USE [master] GO /****** 对象: Database [Test ...

  9. Gson(Google)基础

    一.所需jar包: gson-x.x.jar(本例使用的是gson-2.7.jar). 二.解析转化: 1.json字符串  < ------ >  json String str=&qu ...

  10. 全面理解Java内存模型(转)

    转自:http://blog.csdn.net/suifeng3051/article/details/52611310 Java内存模型即Java Memory Model,简称JMM.JMM定义了 ...