• 技术文章 >运维 >linux运维

    你知道linux下crontab中的%有啥特殊意义吗?

    藏色散人藏色散人2021-09-06 17:26:01转载177
    下面由linux系统教程栏目给大家介绍linux下crontab中%的使用,及其特殊含义,希望对需要的朋友有所帮助!

    linux下crontab中%的使用

    crontab中下面的脚本不能

     0 1 * * *   (cd /u01/prod; rsync -avz app 192.168.0.192:/u01/prod/) &>/home/applprod/backuplog/rsync_`date +%Y%m%d_%H%M%S`.log

    执行的时候,/var/log/messages日志中显示:

    Sep 22 22:50:01 ebsapp CROND[13389]: (applprod) CMD ((cd /u01/prod; rsync -avz app 192.168.0.192:/u01/prod/) &>/home/applprod/backuplog/rsync_`date +)

    好像是命令被截断的样子。

    于是我把要执行的命令都封装到一个脚本中,放到crontab中执行。

    但是稍后查看crontab的manpage时发现,%在crontab中有特殊含义:

    The  "sixth"  field (the rest of the line) specifies the command to be run.  The entire command portion of the line, up to a new-
           line or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile.   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.

    到这里问题已经清楚了,并不是crontab命令被截断,而是被理解成另外的含义了,解决的方法也有了,就是将%进行转义,修改之后的脚本变成了:

    03 23 * * * (cd /u01/prod; rsync -avz app 192.168.0.192:/u01/prod/) &>/home/applprod/backuplog/rsync_`date +\%Y\%m\%d_\%H\%M\%S`.log

    以上就是你知道linux下crontab中的%有啥特殊意义吗?的详细内容,更多请关注php中文网其它相关文章!

    声明:本文转载于:segmentfault,如有侵犯,请联系admin@php.cn删除
    专题推荐:linux crontab
    上一篇:浅析Linux中服务器代码部署篇(分享) 下一篇:一分钟讲解linux下怎么配置samba服务
    大前端线上培训班

    相关文章推荐

    • linux下的crontab命令有什么用法• 让Crontab每秒钟执行一次任务的方法• crontab不执行php怎么办• 带大家学习Linux crontab

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网