Do you know what the special meaning of % in crontab under Linux is?

藏色散人
Release: 2021-09-06 17:26:01
forward
2146 people have browsed it

The following column linux system tutorial will introduce to you the use of % in crontab under Linux and its special meaning. I hope it will be helpful to friends in need!

Do you know what the special meaning of % in crontab under Linux is?

% usage in crontab under Linux

The following script in crontab cannot

 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
Copy after login

During execution, the /var/log/messages log displays:

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 +)
Copy after login

It seems that the command has been truncated.

So I encapsulated all the commands to be executed into a script and put them in crontab for execution.

But when I checked the crontab manpage later, I found that % has a special meaning in 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.
Copy after login

The problem is now clear. It is not that the crontab command is truncated, but is understood as There is another meaning, and the solution is to escape %. The modified script becomes:

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
Copy after login

The above is the detailed content of Do you know what the special meaning of % in crontab under Linux is?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template