Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a limit of characters a command in a crontab could be ?

I have a crontab with a 178 characters command and it seems to be truncated at 164 when executed. I can tell this number from the e-mail I receive and from the vi colors changing from that point.

So, is it an "official" limitation ? I can't find any documentation about this.

share|improve this question
    
Hmm, if it did have a length limit I doubt it would be as low as you're seeing. It would be worth your while working your way through serverfault.com/questions/449651/… and then if it doesn't help update your question with your actual (suitably redacted) crontab entry. –  Iain Oct 16 '13 at 8:47
    
You were right, length was not the problem. See my answer. Thanks for the link. –  Ponytech Oct 16 '13 at 8:51

1 Answer 1

Wow, I found what my problem is and it had nothing to do with line length.

It turns out that my command had a % (percent sign) in it, which has a special meaning in crontab. It is used to input text to STDIN (see Why is my crontab not working, and how can I troubleshoot it?).

So I had to escape it. My command which was:

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

becomes

gzip -c /path/to/a/file > /backup/dir/file-`echo $(date +\%F_\%T)`.gz
share|improve this answer
    
Wouldn't be ... date '+%F_%T' sufficient? –  Jiri Xichtkniha Oct 16 '13 at 9:09
    
I'm guessing he's doing the echo to eliminate the newline character that date puts at the end of its output –  Ed. Oct 16 '13 at 21:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.