Lunghezza massima del comando di Crontab


20

Esiste un limite di caratteri che potrebbe essere un comando in un crontab?

Ho un crontab con un comando di 178 caratteri e sembra essere troncato a 164 quando eseguito. Posso dire questo numero dall'e-mail che ricevo e dai colori vi cambiando da quel punto.

Quindi, è una limitazione "ufficiale"? Non riesco a trovare alcuna documentazione al riguardo.


Hmm, se avesse un limite di lunghezza dubito che sarebbe basso come stai vedendo. Ne varrebbe la pena mentre si lavora attraverso serverfault.com/questions/449651/… e quindi se non aiuta ad aggiornare la domanda con la voce crontab effettiva (opportunamente redatta).
user9517 supporta GoFundMonica il

Avevi ragione, la lunghezza non era il problema. Vedi la mia risposta Grazie per il link
Ponytech,

Risposte:


36

Wow, ho scoperto qual è il mio problema e non ha nulla a che fare con la lunghezza della linea.

Si scopre che il mio comando aveva un% (segno di percentuale), che ha un significato speciale in crontab. Viene utilizzato per inserire testo in STDIN (vedi Perché il mio crontab non funziona e come posso risolverlo? ).

Quindi ho dovuto scappare. Il mio comando che era:

gzip -c /path/to/a/file > /backup/dir/file-$(date +%F_%T).gz

diventa

gzip -c /path/to/a/file > /backup/dir/file-$(date +\%F_\%T).gz

Non sarebbe ... data '+% F_% T' sufficiente?
jirib,

Immagino stia facendo l'eco per eliminare il carattere newline che la data mette alla fine del suo output
Ed.

2
Mi chiedevo perché la modifica del crontab con l'evidenziazione di sintassi e vim rendesse il mio comando un po 'colorato. Ciò ha %causato una costernazione di un paio d'ore!
geerlingguy,

12

Esperienzialmente , esiste un troncamento di 999 caratteri per riga su tutte le mie macchine Ubuntu, anche se non ho ancora trovato alcuna documentazione esplicativa correlata.

Ho testato su Ubuntu 10.04, 12.04 e 14.04 e il conteggio dei 999 caratteri è iniziato dal primo carattere non bianco dopo la pianificazione (nel mio esempio la pianificazione è * * * * *, che equivale a 1 volta al minuto).

Osservare:

  • Per prima cosa contiamo i caratteri del comando che aggiungeremo al nostro crontab - senza il programma :

    davidamick@myputer:~$ echo -n "/bin/echo 'aaaaaaaaaaaaaaaaaaaaa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aaaaaaaaa' > /tmp/test.log" | crontab -
    davidamick@myputer:~$
    
  • Aspetta un minuto, controlla che /tmp/test.logsia stato creato un file contenente tutte le tue "a":

    davidamick@myputer:~$ cat /tmp/test.log
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    davidamick@myputer:~$
    
  • Inizia da capo, rimuovi il file crontab e il registro:

    davidamick@myputer:~$ crontab -r
    davidamick@myputer:~$ rm /tmp/test.log
    davidamick@myputer:~$
    
  • Aggiungi lo stesso comando di prima, solo 1 carattere in più, (nel mio caso, B):

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test.log" | crontab -
    davidamick@myputer:~$
    
  • Aspetta un altro minuto, scopri che un file chiamato è /tmp/test.lostato creato con le tue "a" s. Questo perché il 1000 ° personaggio è stato troncato.
  • Per confermare, rimuovere quello aggiunto Be invece aggiungere 1a al nome file, in questo modo:

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test1.log" | crontab -
    
  • Aspetta un altro minuto, nota che un file chiamato /tmp/test1.loviene creato con le tue "a".
  • Per la prova di bonus, creare un link simbolico da /bin/echoa /usr/bin/echoe trovare voi dovrà rimuovere un ulteriore 4 caratteri dal vostro comando.

3
Ho appena verificato questo, è vero. cronsul mio Ubuntu 14.04 tronca silenziosamente il comando a 999 caratteri. È così pazzesco, mi ci è voluto un po 'per digerirlo. E questo sembra essere l'unico posto su Internet per documentarlo, con 1 voto.
nh2,

Immagina di avere un comando come ... && stop-power-plant; start-power-plante cron semplicemente tagliare in silenzio; start-power-plant
nh2

1
Dopo quasi 30 anni (cron è almeno del 1988), un'anima brillante lo fece lanciare un errore: github.com/systemd-cron/crontab/commit/…
nh2

1
Sembra che Debian avesse una segnalazione di bug per questo: bugs.debian.org/cgi-bin/bugreport.cgi?bug=686223
nh2

Se sei fortunato, il troncamento avviene all'interno di una citazione e ottieni /bin/sh: 1: Syntax error: Unterminated quoted string, ma non c'è nulla che lo garantisca.
nh2,
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.