Discussion:
cron line continuation?
(too old to reply)
Ronald Klop
2021-06-06 11:56:18 UTC
Permalink
Hi,

I'm trying to create a cron entry with line continuation. This document mentions the \ character:
https://docs.freebsd.org/doc/13.0-RELEASE/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/handbook/configtuning-cron.html

The manual pages do not mention this and I can't get it to work.

Is this possible?

Regards,
Ronald.


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Torfinn Ingolfsen
2021-06-06 14:57:38 UTC
Permalink
On Sun, 6 Jun 2021 13:56:18 +0200
Post by Ronald Klop
Hi,
https://docs.freebsd.org/doc/13.0-RELEASE/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/handbook/configtuning-cron.html
The manual pages do not mention this and I can't get it to work.
Is this possible?
'man 5 crontab' has this section
The ``sixth'' field (the rest of the line) specifies the command to be
run. One or more command options may precede the command to modify
processing behavior. The entire command portion of the line, up to a
newline or % character, will be executed by /bin/sh or by the shell
specified in the SHELL variable of the cronfile. Percent-signs (%) in
the command, unless escaped with backslash (\), will be changed into
newline characters, and all data after the first % will be sent to the
command as standard input.

HTH
--
Torfinn Ingolfsen <***@getmail.no>


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Ronald Klop
2021-06-07 07:42:22 UTC
Permalink
Van: Torfinn Ingolfsen <***@getmail.no>
Datum: zondag, 6 juni 2021 16:57
Aan: freebsd-***@freebsd.org
Onderwerp: Re: cron line continuation?
Post by Torfinn Ingolfsen
On Sun, 6 Jun 2021 13:56:18 +0200
Post by Ronald Klop
Hi,
https://docs.freebsd.org/doc/13.0-RELEASE/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/handbook/configtuning-cron.html
The manual pages do not mention this and I can't get it to work.
Is this possible?
'man 5 crontab' has this section
The ``sixth'' field (the rest of the line) specifies the command to be
run. One or more command options may precede the command to modify
processing behavior. The entire command portion of the line, up to a
newline or % character, will be executed by /bin/sh or by the shell
specified in the SHELL variable of the cronfile. Percent-signs (%) in
the command, unless escaped with backslash (\), will be changed into
newline characters, and all data after the first % will be sent to the
command as standard input.
HTH
--
Thank you for your answer. I read that part of the manual page. It says that everything after % is used as standard input. That is not what I'm looking for.

I would like to rewrite this:
@daily freebsd-update -b /data/jails/freebsd13 -d /data/jails/freebsd13/var/db/freebsd-update/ -f /data/jails/freebsd13/etc/freebsd-update.conf --currently-running $( /data/jails/freebsd13/bin/freebsd-version -u) cron && freebsd-update -b /data/jails/freebsd13 -d /data/jails/freebsd13/var/db/freebsd-update/ -f /data/jails/freebsd13/etc/freebsd-update.conf --currently-running $( /data/jails/freebsd13/bin/freebsd-version -u) updatesready > /dev/null && freebsd-update -b /data/jails/freebsd13 -d /data/jails/freebsd13/var/db/freebsd-update/ -f /data/jails/freebsd13/etc/freebsd-update.conf --currently-running $( /data/jails/freebsd13/bin/freebsd-version -u) install

to this:
@daily freebsd-update -b /data/jails/freebsd13 -d /data/jails/freebsd13/var/db/freebsd-update/ -f /data/jails/freebsd13/etc/freebsd-update.conf --currently-running $( /data/jails/freebsd13/bin/freebsd-version -u) cron \
&& freebsd-update -b /data/jails/freebsd13 -d /data/jails/freebsd13/var/db/freebsd-update/ -f /data/jails/freebsd13/etc/freebsd-update.conf --currently-running $( /data/jails/freebsd13/bin/freebsd-version -u) updatesready > /dev/null \
&& freebsd-update -b /data/jails/freebsd13 -d /data/jails/freebsd13/var/db/freebsd-update/ -f /data/jails/freebsd13/etc/freebsd-update.conf --currently-running $( /data/jails/freebsd13/bin/freebsd-version -u) install

which is much better readable. I can't get this to work so the documentation might be inconsistent.

Regards,
Ronald.
Ask Bjørn Hansen
2021-06-07 07:51:41 UTC
Permalink
Post by Ronald Klop
which is much better readable. I can't get this to work so the documentation might be inconsistent.
I don’t think cron supports escaping newline. You can escape % as described, but (as you know) that’s something else.

The standard solution to this is not to write programs in the cron config. Write a script or program elsewhere and have cron execute it.


Ask
Tom Samplonius
2021-06-07 08:58:43 UTC
Permalink
Post by Ask Bjørn Hansen
Post by Ronald Klop
which is much better readable. I can't get this to work so the documentation might be inconsistent.
I don’t think cron supports escaping newline. You can escape % as described, but (as you know) that’s something else.
The standard solution to this is not to write programs in the cron config. Write a script or program elsewhere and have cron execute it.
Yes, “\” as a continuation character is not supported. The cron manpage is correct (no mention of using \ for anything but an escape character). The https://docs.freebsd.org/doc/13.0-RELEASE/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/handbook/configtuning-cron.html <https://docs.freebsd.org/doc/13.0-RELEASE/usr/local/share/doc/freebsd/en_US.ISO8859-1/books/handbook/configtuning-cron.html> page is incorrect.

I’ve also checked the source at https://github.com/freebsd/freebsd-src/blob/373ffc62c158e52cde86a5b934ab4a51307f9f2e/usr.sbin/cron/lib/entry.c There is no code to merge lines ending with a \ into a single command.

And I agree, for a large number of sequential commands, a shell is going to superior is every way. You could also add error recovery, etc.
Post by Ask Bjørn Hansen
Ask
Loading...