Crontab maksimum komut uzunluğu


20

Bir crontab'daki bir komutun olabileceği karakter sınırı var mı?

Ben 178 karakter komut ile bir crontab var ve yürütüldüğünde 164 kesilmiş gibi görünüyor. Bu numarayı aldığım e-postadan ve o noktadan değişen vi renklerinden söyleyebilirim.

Peki, bu "resmi" bir sınırlama mıdır? Bununla ilgili herhangi bir belge bulamıyorum.


Hmm, eğer bir uzunluk sınırı varsa, gördüğünüz kadar düşük olacağından şüpheliyim. Serverfault.com/questions/449651/… yolunda çalışırken ve daha sonra sorunuzu güncel (uygun şekilde düzeltilmiş) crontab girişinizle güncellemeye yardımcı olmazsa sizin için değerlidir .
user9517, GoFundMonica

Haklıydın, uzunluk problem değildi. Cevabımı gör. Bağlantı için teşekkürler.
Ponytech

Yanıtlar:


36

Vay be, sorunumun ne olduğunu buldum ve hat uzunluğu ile ilgisi yoktu.

Komutumun içinde crontab'da özel bir anlamı olan bir% (yüzde işareti) olduğu ortaya çıktı. STDIN'e metin girmek için kullanılır (bkz. Crontab'ım neden çalışmıyor ve nasıl giderebilirim? ).

Bu yüzden kaçmak zorunda kaldım. Benim komutum:

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

olur

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

'+% F_% T' tarihi yeterli olmaz mı?
jirib

Sanırım tarih çıkışının sonuna çıkan yeni satır karakterini ortadan kaldırmak için yankı yapıyor
Ed.

2
Crontab'ı vim ve sözdizimi vurgulama ile düzenlemenin neden komutumu biraz renkli gösterdiğini merak ediyordum. Bu %birkaç saatlik bir şaşkınlığa neden oldu!
geerlingguy

12

Deneysel olarak , henüz herhangi bir ilgili açıklayıcı belge bulamamam rağmen, tüm Ubuntu makinelerimde satır başına 999 karakterlik bir kesme var.

Ubuntu 10.04, 12.04 ve 14.04'te test ettim ve 999 karakter sayısı, programın ötesindeki ilk boşluk olmayan karakterde başlatılır (örneğimde, program * * * * *her dakika 1 kez eşittir).

Gözlemek:

  • İlk önce crontab'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aaaaaaaaaaaaaaa' > /tmp/test.log" | wc -c
    999
    davidamick@myputer:~$
    
  • Her dakika çalıştırmak için bu komutu crontab'ımıza ekleyin: (WARN, ilgili kullanıcı için mevcut crontab girişlerinin üzerine yazar)

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test.log" | crontab -
    davidamick@myputer:~$
    
  • Bir dakika bekleyin, /tmp/test.logtüm "a" larınızı içeren bir dosya oluşturulduğunu kontrol edin :

    davidamick@myputer:~$ cat /tmp/test.log
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    davidamick@myputer:~$
    
  • Yeni başlayın, crontab ve log dosyasını kaldırın:

    davidamick@myputer:~$ crontab -r
    davidamick@myputer:~$ rm /tmp/test.log
    davidamick@myputer:~$
    
  • Önceki komutla aynı komutu ekleyin, yalnızca 1 karakter daha uzun, (benim durumumda B):

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test.log" | crontab -
    davidamick@myputer:~$
    
  • Bir dakika daha bekleyin /tmp/test.lo, "a" larınızla adlı bir dosya oluşturulduğunu bulun. Bunun nedeni 1000'inci karakterin kısaltılmış olmasıdır.
  • Onaylamak için, eklenenleri kaldırın Bve bunun yerine 1dosya adına a ekleyin :

    davidamick@myputer:~$ echo "* * * * * /bin/echo 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > /tmp/test1.log" | crontab -
    
  • Bir dakika daha bekleyin /tmp/test1.lo, "a" larınızla oluşturulmuş bir dosya olduğuna dikkat edin.
  • Bonus ispatı için bir sembolik oluşturmak /bin/echoiçin /usr/bin/echove sizin komuta ek bir 4 karakterleri kaldırmak zorunda kalacak bulabilirsiniz.

3
Bunu doğruladım, bu doğru. cronbenim Ubuntu 14.04 sessizce komutu 999 karakter keser. Bu çok çılgınca, sindirmem biraz zaman aldı. Ve bu, internette 1 yukarı oyla belgelendiren tek yer gibi görünüyor.
nh2

Gibi bir komutun olduğunu düşünün ... && stop-power-plant; start-power-plantve cron sessizce ; start-power-plant
doğrayın

1
Neredeyse 30 yıl sonra (cron en az 1988'den geliyor), bazı parlak ruh bir hata atmasını
sağladı

1
Görünüşe göre debian bunun için bir hata raporu vardı: bugs.debian.org/cgi-bin/bugreport.cgi?bug=686223
nh2

Eğer şanslıysanız, kısaltma bir teklifin içinde gerçekleşir ve alırsınız /bin/sh: 1: Syntax error: Unterminated quoted string, ancak bunu garanti eden hiçbir şey yoktur.
nh2
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.