有群里的小伙伴说crontab里的任务不执行,具体是这样的

*/1 * * * * /bin/date "+%Y-%m-%d %H:%M:%S" >>/data/tmp/test.log

我试了下在命令行可以执行,定时任务确实不执行,于是去翻了下日志:

#tail -f /var/spool/mail/root
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20200108081701.8FD502100481@D3L40.localdomain>
Date: Wed, 8 Jan 2020 16:17:01 +0800 (CST) /bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file From root@D3L40.localdomain Wed Jan 8 16:18:01 2020

说是语法错误,结尾不对,明明是两个双引号啊,这样就有可能是里面有特殊字符导致命令意外中断了,于是查了下万能的百度发现:

The “sixth” field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell’s trailing “”.

大概是在crontab里%当换行符用了,想要正常使用就得加反引号\,\%这样来用。

于是把命令改成了:

*/1 * * * * /bin/date "+\%Y-\%m-\%d \%H:\%M:\%S" >>/data/tmp/test.log

最后:

# cat test.log
2020-01-08 16:38:01
2020-01-08 16:39:01

可以了,于是想着记一下,好记性不如烂笔头嘛。

最新文章

  1. 【记录】ASP.NET MVC JsonResult JsonRequestBehavior AllowGet
  2. Emit学习(2) - IL - 常用指令介绍
  3. sql函数PadLeft与PadRight代码实例
  4. mvc view-controller mvc annotation-driven
  5. 每天php函数 - list()给一组变量赋值
  6. paip.输入法编程----删除双字词简拼
  7. Spring 4.0 中的 WebSocket 架构
  8. [HAOI2011]problem a
  9. 【Spring源码分析】.properties文件读取及占位符${...}替换源码解析
  10. Redis数据结构和常用API
  11. python之socketserver实现并发
  12. 调试webpack配置文件
  13. 第4章 DHCP服务
  14. Qt 编程指南10 QImage Mat QPixmap转换
  15. 使用v-bind处理class与style
  16. 深入浅出LVM on linux
  17. cocos2d-x 3.0 在C++中调用lua函数(2)
  18. FastJson 对enum的 序列化(ordinal)和反序列化
  19. conda 虚拟环境
  20. Navicat Premium v12.0.23.0 破解教程x86,x64通用,手动破解

热门文章

  1. git 回滚到某个版本
  2. js执行代码顺序
  3. NuGet 符号服务器
  4. vue 使用webpack打包后路径报错以及 alias 的使用
  5. jquery核心基础
  6. vue-learning:9-template-v-model
  7. C# 强转空会不会出现异常
  8. Android生命周期函数执行顺序
  9. Android Library的依赖方式及发布(转)
  10. Django的安装命令