crontab条目中包含%号,最常见的取时间,如:date +%d,

对%需要使用\进行转义,否则不能按预期执行,正确做法为:

* * * * * echo "`date +\%d`" > /tmp/r1r.txt

而不能为

* * * * * echo "`date +%d`" > /tmp/r1r.txt

%是crontab的特殊字符,所有%后的被当作了标准输入,这可以通过“ man 5 crontab”查看到说明:

The entire command portion of the line, up to a newline or a "%" character,

will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile.

A "%" character in the command, unless escaped with a backslash (\), 

will be changed into newline char-acters,

and all data after the first % will be sent to the command as standard input.

示例:

$ cat /tmp/hello.txt 

cat: /tmp/hello.txt: 没有那个文件或目录

$ echo -e "`crontab -l`\n* * * * * cat > /tmp/hello.txt % hello word"|crontab -

$ crontab -l|grep hello.txt

* * * * * cat > /tmp/hello.txt % hello word

$ cat /tmp/hello.txt 

 hello word

crontab条目包含%号问题的更多相关文章

  1. 【HTTP】http请求url参数包含+号,被解析为空格

    项目技术:Angular 6 问题现象:接口传参的时候,使用 httpClient.post 方法提交数据,字段中包含+号被解析成空格,提交数据错误 解决过程: 1.http请求中包含+号,会被自动解 ...

  2. jmeter问题处理随笔1 - CSV取值数据异常处理(包含"号,","号的情况)

    背景 jmeter测试中通过CSV进行用例数据的管理,在result断言中间需要使用json格式的数据,会包含 " ",",这个时候发现CSV取值会报错或者乱码 解决 用 ...

  3. js传递参数中包含+号时的处理方法

    encodeURI(url).replace(/\+/g, '%2B') 例子: $scope.getAnesthesiawaystatistical = function (annual, anes ...

  4. 自学Linux Shell15.2-作业控制命令(jobs/bg/nice/renice/at/atp/atrm/crontab)

    点击返回 自学Linux命令行与Shell脚本之路 15.1-作业控制命令(jobs/bg/nice/renice/at/atp/atrm/crontab) 1  控制作业 1.1查看作业 (jobs ...

  5. Linux crontab 定时任务命令详解

    一.简介 crontab 命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于 crontab 文件中,以供之后读取和执行.通常,crontab 储存的指令被守护进程激活, cr ...

  6. Linux新手学堂 Crontab命令的语法

    crontab 命令的用途就是:提交.编辑.列出或除去 cron 作业. 语法 crontab [ -e [UserName] | -l [UserName] | -r [UserName] | -v ...

  7. linux crontab定时执行shell脚本

    linux下使用crontab命令被用来提交和管理用户的需要周期性执行的任务,示例如下:crontab -e 编辑周期任务30 21 * * * /etc/init.d/smb restart 每晚的 ...

  8. Linux Crontab 任务管理工具命令以及示例

    Crontab 是 Linux 平台下的一款用于循环执行例行任务的工具,Linux 系统由 cron (crond) 这个系统服务来控制任务 , Linux系统本来就有很多的计划任务需要启动 , 所以 ...

  9. shell 中的 eval 及 crontab 命令

    eval eval会对后面的命令进行两遍扫描,如果第一遍扫描后,命令是个普通命令,则执行此命令:如果命令中含有变量的间接引用,则保证间接引用的语义.也就是说,eval命令将会首先扫描命令行进行所有的置 ...

随机推荐

  1. Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools"

    https://blog.csdn.net/saucyj/article/details/79043443

  2. linux操作系统-设置静态ip

    在使用linux虚拟机的时候因为经常有关机的需求,然后重新开机后可能面临这上一次获取的ip被改变,在这里我分享一下在linux 下设置静态ip的经验 1.查看路由状态 [root@localhost ...

  3. js filter关键字

    filter filter也是一个常用的操作,它用于把Array的某些元素过滤掉,然后返回剩下的元素. 和map()类似,Array的filter()也接收一个函数.和map()不同的是,filter ...

  4. laravel框架一次请求的生命周期

    第一件事所有的请求都会被web服务器(Apache/Nginx)导向public/index.php文件.index.php文件载入Composer生成的自动加载设置,然后从bootstrap/app ...

  5. PAT 1014 福尔摩斯的约会 (20)(代码+思路)

    1014 福尔摩斯的约会 (20)(20 分) 大侦探福尔摩斯接到一张奇怪的字条:"我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfd ...

  6. iOS.Crash.Case-[__NSArrayM objectForKeyedSubscript:]

    1. [__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance - source code and s ...

  7. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed问题解决

    https://zeroturnaround.com/forums/topic/jrebel-reports-more-than-one-version-of-org-apache-commons-l ...

  8. POJ 2762 Going from u to v or from v to u?- Tarjan

    Description 判断一个有向图是否对于任意两点 $x$,  $y$ 都有一条路径使$x - >y$或 $y - >x$ Solution 对于一个强联通分量内的点 都是可以互相到达 ...

  9. Luogu 3119 [USACO15JAN]草鉴定Grass Cownoisseur

    思路很乱,写个博客理一理. 缩点 + dp. 首先发现把一个环上的边反向是意义不大的,这样子不但不好算,而且相当于浪费了一次反向的机会.反正一个强连通分量里的点绕一遍都可以走到,所以我们缩点之后把一个 ...

  10. Vim中如何使用正则进行搜索

    #set magic这句的作用在于将vim的正则打开. 这样就可以搜索了. 至于正则的相关的内容.在此抄一份.以免于下次自己还要去百度. 符号 匹配 . (dot) 任意单一字符 \d 任意一位数字 ...