Crontab 최대 명령 길이


20

crontab의 명령에는 문자 수가 제한되어 있습니까?

178 문자 명령이있는 crontab이 있으며 실행시 164에서 잘린 것처럼 보입니다. 이 번호는 내가받은 이메일과 그 시점에서 바뀌는 vi 색상에서 알 수 있습니다.

"공식적인"제한입니까? 이것에 관한 문서를 찾을 수 없습니다.


흠, 길이 제한이 있다면 당신이보고있는 것보다 낮을 것입니다. serverfault.com/questions/449651/…을 통해 작업하는 동안 실제 (적절하게 수정 된) crontab 항목으로 질문을 업데이트하는 데 도움이되지 않으면 가치가 있습니다 .
user9517은 GoFundMonica 지원

네 말이 맞아 길이는 문제가 아니야 내 대답을 참조하십시오. 링크 주셔서 감사합니다.
Ponytech

답변:


36

와우, 나는 내 문제가 무엇인지 발견했고 그것은 줄 길이와 관련이 없었습니다.

내 명령에는 % (퍼센트 기호)가있어 crontab에서 특별한 의미가 있습니다. STDIN에 텍스트를 입력하는 데 사용됩니다 (크론 탭 이 작동하지 않는 이유 및 문제 해결 방법 참조).

그래서 나는 그것을 피해야했다. 내 명령은 다음과 같습니다.

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

된다

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

... 날짜 '+ % F_ % T'이면 충분하지 않습니까?
jirib

나는 그가 개행 문자를 제거하기 위해 에코을하는 것 같은데요 그 출력의 마지막 날짜 풋
에드.

2
vim과 구문 강조를 사용하여 crontab을 편집하면 명령이 조금 화려하게 보이는 이유가 궁금합니다. %발생 몇 시간 '경악!
geerlingguy

12

경험적으로 , 모든 Ubuntu 시스템에서 줄당 999 문자 잘림이 있지만 관련 설명 문서는 아직 찾지 못했습니다.

우분투 10.04, 12.04 및 14.04에서 테스트했으며 999 문자 수가 일정 이후 첫 번째 공백 문자가 아닌 문자에서 시작됩니다 (예제에서는 일정은 * * * * *1 분마다 1입니다).

관찰 :

  • 먼저 스케줄없이 crontab에 추가 할 명령의 문자를 계산합니다 .

    davidamick@myputer:~$ echo -n "/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aaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test.log" | crontab -
    davidamick@myputer:~$
    
  • 1 분 정도 기다렸다가 /tmp/test.log"a"가 모두 포함 된 파일이 생성 되었는지 확인하십시오 .

    davidamick@myputer:~$ cat /tmp/test.log
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    davidamick@myputer:~$
    
  • 새로 시작하고 crontab 및 로그 파일을 제거하십시오.

    davidamick@myputer:~$ crontab -r
    davidamick@myputer:~$ rm /tmp/test.log
    davidamick@myputer:~$
    
  • 이전과 동일한 명령을 1 자만 더 추가하십시오 (제 경우에는 B) :

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test.log" | crontab -
    davidamick@myputer:~$
    
  • 잠시 후에 /tmp/test.lo"a"로 이름 이 지정된 파일을 찾으십시오 . 1000 번째 문자가 잘 렸기 때문입니다.
  • 확인하려면 B추가 된 1파일을 제거 하고 대신 파일 이름 에 a 를 추가하십시오 .

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test1.log" | crontab -
    
  • 1 분 정도 기다렸다가 /tmp/test1.lo"a"로 이름 이 지정된 파일 이 생성됩니다.
  • 보너스 증거를 들어,에서 심볼릭 링크 생성 /bin/echo에를 /usr/bin/echo당신이 당신의 명령에서 추가로 4 개 문자를 제거해야합니다 찾을 수 있습니다.

3
방금 이것을 확인했지만 사실입니다. cron내 우분투 14.04에서 자동으로 명령을 999 자로 자릅니다. 이건 너무 견디기 때문에 소화하는데 시간이 걸렸습니다. 그리고 이것은 인터넷상에서 유일하게 공짜로 문서를 기록한 유일한 장소 인 것 같습니다.
nh2

... && stop-power-plant; start-power-plantcron 과 같은 명령이 있고 cron이 조용히 잘 ; start-power-plant
린다고

1
: 거의 30 세 (크론은 적어도 1988입니다) 후 일부 밝은 영혼은 오류 던져 만든 github.com/systemd-cron/crontab/commit/...
NH2

1
데비안이 이것에 대한 버그 리포트를 가지고있는 것 같습니다 : bugs.debian.org/cgi-bin/bugreport.cgi?bug=686223
nh2

운이 좋으면 잘림이 따옴표 안에 들어가고 얻을 수 /bin/sh: 1: Syntax error: Unterminated quoted string는 있지만 보장하는 것은 없습니다.
nh2
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.