Maison  >  Article  >  Opération et maintenance  >  Savez-vous quelle est la signification particulière de % dans crontab sous Linux ?

Savez-vous quelle est la signification particulière de % dans crontab sous Linux ?

藏色散人
藏色散人avant
2021-09-06 17:26:012079parcourir

La colonne suivante du tutoriel du système Linux vous présentera l'utilisation de % dans crontab sous Linux et sa signification particulière. J'espère qu'elle sera utile aux amis dans le besoin !

Savez-vous quelle est la signification particulière de % dans crontab sous Linux ?

% de l'utilisation dans crontab sous Linux

Le script suivant dans crontab ne peut pas

 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

Une fois exécuté, le journal /var/log/messages affiche :

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 +)

Il semble que la commande ait été tronqué.

J'ai donc encapsulé toutes les commandes à exécuter dans un script et les ai mises dans crontab pour exécution.

Mais quand j'ai vérifié la page de manuel de crontab plus tard, j'ai découvert que % a une signification particulière dans 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.

Le problème est maintenant clair. Ce n'est pas que la commande crontab est tronquée, mais est comprise comme ayant une autre signification. solution Oui, échappez simplement %, et le script modifié devient :

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

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer