pfSense Support Subscription

Author Topic: cron command execution is broken partially  (Read 263 times)

0 Members and 1 Guest are viewing this topic.

Offline w0w

  • Sr. Member
  • ****
  • Posts: 559
  • Karma: +35/-6
  • kernel panic attack
    • View Profile
cron command execution is broken partially
« on: December 21, 2017, 10:50:39 am »
Looks like the input field for the command is not limited to appropriate length and command got truncated when exceeds some limit used by cron. It would be very useful to limit input length according to maximum allowed by cron or at least developers can add note about limited length.
Does anybody knows what maximum command length is acceptable by cron?
« Last Edit: December 22, 2017, 12:35:51 pm by w0w »

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 21495
  • Karma: +1458/-26
    • View Profile
Re: Cron package maximum lenght for command input field?
« Reply #1 on: December 22, 2017, 08:25:44 am »
I'm not aware of a limit specifically in cron, but in general the command line limit varies from shell to shell. The man page for crontab(5) doesn't mention a limit.

Past a certain point though you should be using a script and not a gigantic command line.
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline w0w

  • Sr. Member
  • ****
  • Posts: 559
  • Karma: +35/-6
  • kernel panic attack
    • View Profile
Re: Cron package maximum lenght for command input field?
« Reply #2 on: December 22, 2017, 12:28:28 pm »
Sorry for bothering you, jimp. I did not find this limit anywhere documented also and I using script now, but I just wanted to hold all my settings in config file, my command length was ~ 243 chars and I started playing with echo command posting some output via cron to a file. I have just found that it's not length but just lack of necessary knowledge on my side and some cron bug/features, because it runs only half (first 4) of multiple sequental commands via cron and same sequence runs just fine till the end via shell.
Code: [Select]
zfs snapshot -r zroot@currentsnap && zfs send -R zroot@currentsnap | gzip > /root/backup/currentsnap.gz && zfs destroy -r zroot@currentsnap && curl --upload-file /root/backup/currentsnap.gz ftp://pf@10.0.88.3:2121 && rm /root/backup/currentsnap.gz
No matter what I have tried it run untill "&& curl..." and then just stops. If I run similar #!/bin/sh script or directly in shell it works. I think there is something else in cron that just don't like this command sequence.
« Last Edit: December 22, 2017, 10:56:43 pm by w0w »

Offline w0w

  • Sr. Member
  • ****
  • Posts: 559
  • Karma: +35/-6
  • kernel panic attack
    • View Profile
Re: cron command execution is broken partially
« Reply #3 on: December 22, 2017, 11:31:50 pm »
Tried to add path
Code: [Select]
/sbin/zfs snapshot -r zroot@currentsnap && /sbin/zfs send -R zroot@currentsnap | /usr/bin/gzip > /root/backup/currentsnap.gz && /sbin/zfs destroy -r zroot@currentsnap && /usr/local/bin/curl --upload-file /root/backup/currentsnap.gz ftp://pf@10.0.88.3:2121 && /bin/rm /root/backup/currentsnap.gz
Not helped.

At the end I got it working via bash package

 
Code: [Select]
/usr/local/bin/bash -c 'zfs snapshot -r zroot@currentsnap && zfs send -R zroot@currentsnap | gzip > /root/backup/currentsnap.gz && zfs destroy -r zroot@currentsnap && curl --upload-file /root/backup/currentsnap.gz ftp://pf@10.0.88.3:2121 && rm /root/backup/currentsnap.gz'