alseambusher / crontab-ui

Easy and safe way to manage your crontab file
https://lifepluslinux.blogspot.com/2015/06/crontab-ui-easy-and-safe-way-to-manage.html
MIT License
2.88k stars 478 forks source link

Reduce command length: Error: command too long; while reading crontab for user root #203

Closed LordMike closed 1 year ago

LordMike commented 2 years ago

Make sure these boxes are checked( - [x] ) before submitting an issue.

Hey,

I had a cron job that started failing, and I found out why. The error in crons logs was Error: command too long; while reading crontab for user root. Turns out cron has a length limit on commands that is 999 chars. My command is about 370 chars, but with error/stdout logging, the command in cron becomes 1.038 chars.

I'm thinking that crontabui should warn about this, refuse to write out the file, or maybe there is a way to limit the length of the command?

My command is this:

kopia snapshot create /var/lib/docker/volumes/web-nemligmbwarezdk_db/ /var/lib/docker/volumes/postgresql_pgadmin-data/ /var/lib/docker/volumes/queue_queue-data/ /var/lib/docker/volumes/homeassistant_node-red-data/ /var/lib/docker/volumes/webghmonitormbwarezdk_appdata/ && curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/REDACTED;

Crontabui makes that this:

0 1 0 ((({ kopia snapshot create /var/lib/docker/volumes/web-nemligmbwarezdk_db/ /var/lib/docker/volumes/postgresql_pgadmin-data/ /var/lib/docker/volumes/queue_queue-data/ /var/lib/docker/volumes/homeassistant_node-red-data/ /var/lib/docker/volumes/webghmonitormbwarezdk_appdata/ && curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/REDACTED; } | tee /var/spool/cron/crontabs/32MimKQOvHpX1PwJ.stdout) 3>&1 1>&2 2>&3 | tee /var/spool/cron/crontabs/32MimKQOvHpX1PwJ.stderr) 3>&1 1>&2 2>&3); if test -f /var/spool/cron/crontabs/32MimKQOvHpX1PwJ.stderr; then date >> "/mnt/systems/crontabui/data/logs/32MimKQOvHpX1PwJ.log"; cat /var/spool/cron/crontabs/32MimKQOvHpX1PwJ.stderr >> "/mnt/systems/crontabui/data/logs/32MimKQOvHpX1PwJ.log"; fi; if test -f /var/spool/cron/crontabs/32MimKQOvHpX1PwJ.stdout; then date >> "/mnt/systems/crontabui/data/logs/32MimKQOvHpX1PwJ.stdout.log"; cat /var/spool/cron/crontabs/32MimKQOvHpX1PwJ.stdout >> "/mnt/systems/crontabui/data/logs/32MimKQOvHpX1PwJ.stdout.log"; fi

I have the following:

Example command:

LOGT=/var/spool/cron/crontabs LOGS=/mnt/systems/crontabui/data/logs 0 1 0 ((({ kopia snapshot create /var/lib/docker/volumes/web-nemligmbwarezdk_db/ /var/lib/docker/volumes/postgresql_pgadmin-data/ /var/lib/docker/volumes/queue_queue-data/ /var/lib/docker/volumes/homeassistant_node-red-data/ /var/lib/docker/volumes/webghmonitormbwarezdk_appdata/ && curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/REDACTED; } | tee $LOGT/32MimKQOvHpX1PwJ.stdout) 3>&1 1>&2 2>&3 | tee $LOGT/32MimKQOvHpX1PwJ.stderr) 3>&1 1>&2 2>&3); if test -f $LOGT/32MimKQOvHpX1PwJ.stderr; then date >> "$LOGS/32MimKQOvHpX1PwJ.log"; cat $LOGT/32MimKQOvHpX1PwJ.stderr >> "$LOGS/32MimKQOvHpX1PwJ.log"; fi; if test -f $LOGT/32MimKQOvHpX1PwJ.stdout; then date >> "$LOGS/32MimKQOvHpX1PwJ.stdout.log"; cat $LOGT/32MimKQOvHpX1PwJ.stdout >> "$LOGS/32MimKQOvHpX1PwJ.stdout.log"; fi

This command, where you put in the common paths, reduces the original 1.038 chars to 788 chars.

Mike.

alseambusher commented 2 years ago

Good idea.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.