Discussion:
What's wrong with this entry in a cron job?
(too old to reply)
Freek de Kruijf
2024-03-30 11:00:01 UTC
Permalink
I have the following line in a cron job:

1 1 * * * rm -v /srv/db/webhoneypot-$(date --date=yesterday +%Y-%m-%d).json

I get in the journal:

Mar 30 01:01:01 rpi4rasphon CRON[1254]: (root) CMD (rm -v /srv/db/webhoneypot-
$(date --date=yesterday +)

and in the e-mail

/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")
--
fr.gr.

Freek de Kruijf
Leigh Brown
2024-03-30 11:50:02 UTC
Permalink
Hello,
Post by Freek de Kruijf
1 1 * * * rm -v /srv/db/webhoneypot-$(date --date=yesterday
+%Y-%m-%d).json
Mar 30 01:01:01 rpi4rasphon CRON[1254]: (root) CMD (rm -v
/srv/db/webhoneypot-
$(date --date=yesterday +)
and in the e-mail
/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")
man 5 crontab says:
[..]
The ``sixth'' field (the rest of the line) specifies the command
to be
run. 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, un‐
less escaped with backslash (\), will be changed into newline
charac‐
ters, and all data after the first % will be sent to the
command as
standard input.

Regards,

Leigh.
Freek de Kruijf
2024-03-30 12:20:01 UTC
Permalink
Post by Leigh Brown
Hello,
Post by Freek de Kruijf
1 1 * * * rm -v /srv/db/webhoneypot-$(date --date=yesterday
+%Y-%m-%d).json
Mar 30 01:01:01 rpi4rasphon CRON[1254]: (root) CMD (rm -v
/srv/db/webhoneypot-
$(date --date=yesterday +)
and in the e-mail
/bin/sh: 1: Syntax error: end of file unexpected (expecting ")")
[..]
The ``sixth'' field (the rest of the line) specifies the command
to be
run. 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, un‐
less escaped with backslash (\), will be changed into newline
charac‐
ters, and all data after the first % will be sent to the
command as
standard input.
Regards,
Leigh.
Thanks. Would never have imaged this is the case.
--
vr.gr.

Freek de Kruijf
Loading...