crontab里的特殊符号%导致命令不能执行
有群里的小伙伴说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
可以了,于是想着记一下,好记性不如烂笔头嘛。
crontab里的特殊符号%导致命令不能执行的更多相关文章
- 解决python执行linux查看文件命令后,因为^@特殊符号导致部分内容不显示的问题
问题现象 文件a的内容如下: 查看第3行到第5行的内容:sed -n '3,5p' /tmp/test/a 可见在命令行执行,是没有问题的. 在python中使用paramiko模块执行linux命令 ...
- 脚本在Shell可以执行成功,放到crontab里执行失败
一.背景 自己写了个监控MGR状态的脚本,直接在Linux的Shell环境下可以执行成功,但是只要放到crontab里执行,就失败,脚本内容如下 #!/bin/bash MAIL_ADDR=`cat ...
- OSX系统添加定时任务 Linux crontab命令 定时执行py 文件 任务
#输出日志 #将日志输入到2.log文件中无论错误还是正确02 15 * * * . ~/xad/pyenv/xadserver/bin/activate && cd /root/xa ...
- 解决命令行执行shell脚本成功,但crontab执行失败
实际生产案例 生产机房自建PPTP客户端通过拨号连接到生产机房,但是一旦客户端网络是意外断线再重新拨号 会产生IP冲突,于是写了一个脚本监控PPTP的IP是否有多个(一般冲突以后会生成2个IP) #! ...
- Shell里的特殊符号
Shell里的特殊符号: (1)单引号: 由单引号括起来的符号都作为普通字符处理,他们都失去了特殊意义. (2)双引号: 除美元符号($).倒引号.反斜线(\)仍保留特殊含义外,其余符号都作为普通字符 ...
- crontab 里不能运行expdp
编辑脚本 xxx.sh #!/bin/shrq=`date +%Y%m%d`filename="test$rq"expdp system/*** directory=expdump ...
- 多命令顺序执行,dd命令,管道|,grep,通配符,其他特殊符号
多命令顺序执行:命令1;命令2 命令之间没有逻辑关系 命令1&&命令2 命令1执行正确才执行命令2,命令1执行错误不会执行命令2 命令1||命令2 命令执行错误才执行命令2,命令1执行 ...
- docker rmi 导致后面的命令不执行问题 Dockerfile设置时区问题
docker rmi 导致后面的命令不执行问题 把ca=`docker rmi sendemail-service` echo $ca改成docker rmi sendemail-service -f ...
- shell特殊符号cut命令 sort_wc_uniq命令 tee_tr_split命令 shell特殊符号
shell特殊符号cut命令 特殊符号 * 通配符,任意个任意字符 ? 任意一个字符 # 注释字符 \ 脱义字符 c=\$a\$b echo $c | 管道符 cat 1.txt |less ...
随机推荐
- Python--day33--当面试时候问到如何解决黏包问题?的回答。
- 12174 - Shuffle——[滑动窗口]
You are listening to your music collection using the shuffle function to keep the music surprising. ...
- Linux 基础(一)stat函数
Header file: #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> DEFI ...
- linux 选择 ioctl 命令
在为 ioctl 编写代码之前, 你需要选择对应命令的数字. 许多程序员的第一个本能的反 应是选择一组小数从0或1 开始, 并且从此开始向上. 但是, 有充分的理由不这样做. ioctl 命令数字应当 ...
- CF1220
CF1220 A one和zero特的字母分别是'n'和'z' 输出他们的数量即可 #include<cstdio> #include<iostream> #include&l ...
- dotnet 通过 WMI 获取指定进程的输入命令行
本文告诉大家如何使用 WMI 通过 Process 获取这个进程传入的命令行 使用下面代码,使用 Win32_Process 拿到所有的进程,通过 WHERE 判断当前的进程,然后拿到进程传入的命令 ...
- How to output the target message in dotnet build command line
How can I output my target message when I using dotnet build in command line. I use command line to ...
- Android3_了解Gradle工具
一.Gradle Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建开源工具.它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,目前也增加了基于K ...
- Vue通讯
vue组件通讯 #props传递数据 父->子 //父组件传递数据 <template> <Children :data="msg"></Chi ...
- lombok优缺点
优点: 能通过注解的形式自动生成构造器.getter/setter.equals.hashcode.toString等方法,提高了一定的开发效率 让代码变得简洁,不用过多的去关注相应的方法 属性做修改 ...