Heim  >  Artikel  >  Betrieb und Instandhaltung  >  Wissen Sie, was die besondere Bedeutung von % in crontab unter Linux ist?

Wissen Sie, was die besondere Bedeutung von % in crontab unter Linux ist?

藏色散人
藏色散人nach vorne
2021-09-06 17:26:012079Durchsuche

Der folgende Abschnitt der Kolumne „Linux-System-Tutorial“ stellt Ihnen die Verwendung von % in crontab unter Linux und seine besondere Bedeutung vor. Ich hoffe, dass es für Freunde in Not hilfreich ist!

% der Nutzung in Crontab unter Linux Wissen Sie, was die besondere Bedeutung von % in crontab unter Linux ist?

Das folgende Skript in Crontab kann nicht

 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
Bei der Ausführung wird im /var/log/messages-Protokoll Folgendes angezeigt:
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 +)

Es scheint, dass der Befehl ausgeführt wurde abgeschnitten.

Also habe ich alle auszuführenden Befehle in einem Skript gekapselt und zur Ausführung in crontab abgelegt.

Aber als ich später die Crontab-Manpage überprüfte, stellte ich fest, dass % in crontab eine besondere Bedeutung hat:

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.

Das Problem ist jetzt nicht klar, dass der Crontab-Befehl eine andere Bedeutung hat Lösung Ja, einfach % entkommen, und das geänderte Skript lautet:

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

Das obige ist der detaillierte Inhalt vonWissen Sie, was die besondere Bedeutung von % in crontab unter Linux ist?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:segmentfault.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen