创建crontab任务

参考:https://www.cnblogs.com/Icanflyssj/p/5138851.html

3. crontab常用的几个命令格式

crontab -l //显示用户的crontab文件的内容

crontab -e //编辑用户的crontab文件的内容

crontab -r //删除用户的crontab文件

-------

在第一次使用crontab -e,会要求选择编辑器,我选择是vim.basic

编辑文件,内容如下

root@ubuntu:/var/log# crontab -e
# 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 a.m every week with:
# * * tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab() and cron()
#
# m h dom mon dow command
* * * * * /home/xwdreamer/eclipse-workspace/RELEASED_V2_10_20180331/iotkit-embedded/output/release/bin/linkkit-example

其他间隔执行时间设定

每分钟执行      * * * * *
每五分钟执行 */ * * * *
每小时执行 * * * *
每天执行 * * *
每周执行 * *
每月执行 * *
每年执行 *

日志服务

参考:https://blog.csdn.net/ggz631047367/article/details/50185425

ubuntu默认没有开启cron日志记录 
1. 修改rsyslog 
sudo vim /etc/rsyslog.d/50-default.conf 
cron.* /var/log/cron.log #将cron前面的注释符去掉 
2.重启rsyslog 
sudo service rsyslog restart 
3.查看crontab日志 
less /var/log/cron.log

注意:这里必须重启日志服务,重启以后使用less查看可能还没有日志,需要等任务执行以后才能看到日志。

查看cron日志

vim /var/log/cron.log 

在日志中找到

No MTA installed, discarding output 

解决方案:将日志输出到指定文件

*/ * * * * /home/xwdreamer/iotkit/linkkit-example_INV/linkkit-example_INV > linkkit-example_INV_temp.log

完整如下

root@ubuntu:~# crontab -e
# 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 a.m every week with:
# * * tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab() and cron()
#
# m h dom mon dow command
*/ * * * * /home/xwdreamer/iotkit/linkkit-example_INV/linkkit-example_INV > linkkit-example_INV_temp.log
*/ * * * * /home/xwdreamer/iotkit/linkkit-example_penguan/linkkit-example_penguan > linkkit-example_penguan_temp.log

最后日志会被输出到当前账户下的目录,比如当前这个文件被输出到/root目录下

root@ubuntu:/home/xwdreamer/iotkit# find / -name linkkit-example_INV_temp.log
find: ‘/run/user//gvfs’: Permission denied
/root/linkkit-example_INV_temp.log
find: ‘/mnt/hgfs’: Protocol error

ubuntu下使用crontab的更多相关文章

  1. Ubuntu下使用crontab部署定时任务

    Ubuntu下使用crontab部署定时任务 安装cron apt-get install cron 开启crontab日志 默认情况下的日志是没有开启的,我们需要找到 /etc/rsyslog.d/ ...

  2. Ubuntu下用crontab 部署定时任务

    用php做了一个网站,其中一个统计工能,需要每周定时用行.想看看有什么方法,之前看别人的东西,一般有2中方式,一个是php自带的定时任务,一个是用系统 带的,linux下的crontab和window ...

  3. ubuntu下使用crontab定时器

    crontab 定时工具(周期性执行的任务列表称为Cron Table),其中每一个任务,被称为Cron Job. 可以,每分钟执行,每小时执行,每天执行,每周执行,每月执行. 检查服务 1.查看任务 ...

  4. Ubuntu下的计划任务 -- cron的基本知识

    下面不完全: 参考:http://blog.csdn.net/cuker919/article/details/6336457 cron是一个Linux下的后台进程,用来定期的执行一些任务.因为我用的 ...

  5. ubuntu下crontab编辑方法的设定

    在ubuntu下,首次编辑crontab计划任务的时候,会提示让选择编辑器.由于对nano编辑器不是很熟悉,若是选择nova编辑的话,会有些麻烦.可以重置编辑器,方法如下:[root@wang ~]# ...

  6. 【linux】ubuntu下crontab无效解决方法

    在Debain的docker中启用crontab,踩了一整天的坑,特地记录一下.Debain和ubuntu差不多,故算在ubuntu下面了. 1.第一个坑,安装crontab apt-get inst ...

  7. Ubuntu下crontab命令的用法

    cron是一个Linux下的后台进程,用来定期的执行一些任务.因为我用的是Ubuntu,所以这篇文章中的所有命令也只能保证在Ubuntu下有效,但其他系统应该也差不多. 想要让cron执行你指定的任务 ...

  8. 如何在win10下使用Ubuntu中的crontab自动执行任务

    win10下如何下载ubuntu 1.打开Microsoft Store,搜索ubuntu,选择其一(我选了第一个),点击获取,耐心等待安装即可:   2.安装完成可在开始栏找到:   使用cront ...

  9. Ubuntu下定时任务和自启动任务的部署

    1.定时任务的部署,最简单的方法是执行 crontab -e 然后在下面加上世间周期配置和要执行的命令,一般情况下,可以把要执行的任务用bash脚本封装一下,格式如下所示: minute   hour ...

随机推荐

  1. 洛谷---小L和小K的NOIP考后放松赛

    链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...

  2. zabbix邮箱报警设置&问题汇总

    zabbix邮件报警部署! Zabbix监控服务端.客户端都已经部署完成,被监控主机已经添加,Zabiix监控运行正常,通过查看Zabbix监控服务器,可以了解服务器的运行状态是否正常,运维人员不会时 ...

  3. ip 命令

    Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命 ...

  4. vue中的provide/inject的学习使用

    irst:定义一个parent component ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <template>  <div> ...

  5. 防止vs编译时自动启动单元测试

    Tools → Options → Live Unit Testing   Pause 勾选

  6. 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。

    示例 1: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋转 1 步: [7,1,2,3,4,5,6] 向右旋转 2 步: [6,7,1 ...

  7. Pytorch安装(基于anaconda虚拟环境)

    Pytorch安装倒腾了一上午终于搞定,记录一下安装过程. 1. 首先尝试官网的安装方式,但是网速太慢了. 除去cudnn100, torchvision和pytorch三个文件,其余可以直接从清华镜 ...

  8. JS变量声明方式

    在JavaScript中有三种声明变量的方式:const  var let const:用于声明常量.注意:定义的变量的时候,必须同时初始化,且其值之后不可以修改. var:最常用的声明变量关键字.  ...

  9. c#一步一步实现ORM

    本篇适合新手了解学习orm.欢迎指正,交流学习. 现有的优秀的orm有很多. EF:特点是高度自动化,缺点是有点重. Nhibnate:缺点是要写很多的配置. drapper:最快的orm.但是自动化 ...

  10. 分布式缓存技术redis系列(二)——详细讲解redis数据结构(内存模型)以及常用命令

    https://www.cnblogs.com/hjwublog/p/5639990.html