cron job parameters only work for type "script"

Started by drosophila, April 09, 2026, 04:20:35 AM

Previous topic - Next topic
April 09, 2026, 04:20:35 AM Last Edit: April 09, 2026, 04:59:04 AM by drosophila
The type "script_output" doesn't pass on the parameters at all, while the type "stream_output" produces errors like those:
configd.py 24357 - [meta sequenceId="1"] [ed0118b6-cc66-4999-8f9f-ba9f9d59ced2] reordering IPv6 on interface re1...
configd.py 24357 - [meta sequenceId="2"] [ed0118b6-cc66-4999-8f9f-ba9f9d59ced2] Script action failed with [Errno 9] Bad file descriptor at Traceback (most recent call last):   File "/usr/local/opnsense/service/modules/actions/stream_output.py", line 70, in execute     callback(key.fileobj, mask)     ~~~~~~~~^^^^^^^^^^^^^^^^^^^   File "/usr/local/opnsense/service/modules/actions/stream_output.py", line 48, in stdout_reader     connection.send(data)     ~~~~~~~~~~~~~~~^^^^^^ OSError: [Errno 9] Bad file descriptor  (bytes processed 34)
configd.py 24357 - [meta sequenceId="3"] message ed0118b6-cc66-4999-8f9f-ba9f9d59ced2 [ipv6reorder reload re1] returned Execute error

The action file is this:
[reload]
parameter:%s
message:reordering IPv6 on interface %s...
command:/root/priorizeprivacy.sh
type:script
description:Reorder IPv6 addresses to priorize the PEA

The type "script" is the only one that works properly, but none of the other two.

What am I doing wrong this time?

Use script.

Cron doesn't process output anyway and both script_output and stream_output produce output.


Cheers,
Franco

April 09, 2026, 06:52:18 PM #2 Last Edit: April 09, 2026, 07:17:37 PM by drosophila
Thanks for the clarification! So that's why the log messages are truncated when using script_output. I've wasted several hours trying to find out why it wouldn't pass on the parameters like it should until I tried the other types. There's not much to be found about these cron jobs in conjunction with configd, and nobody uses parameters it seems, only a few (2, IIRC) internal scripts seem to so I kept thinking I'd missed the description of some special syntax that might be required. I did find an old thread (this one) where someone was successfully using the parameters with type script_output, so I expected the error was with my lack of understanding. I still seem to be missing something about the parameters / their syntax as the above script obviously works with type script_output while for me it just won't pass the parameter at all, I always get an empty parameter for $1.

So, since this is cleared up (in a way), can I use the internal interface aliases, like "WAN" in the cron parameters somehow, and if so, how? Would be really handy. :)

> nobody uses parameters it seems, only a few (2, IIRC) internal scripts seem to

Yes, that's true for cron-visible actions (tagged with description: in the actions.conf file).  Also documented as such in the manual:

https://docs.opnsense.org/manual/settingsmenu.html#cron

It's also that the parameter passing from cron isn't ideal for multiple parameters but we want to change that, see

https://github.com/opnsense/core/issues/10075

> So, since this is cleared up (in a way), can I use the internal interface aliases, like "WAN" in the cron parameters somehow, and if so, how? Would be really handy. :)

Instructions unclear: what does your script do and what do you want to pass? internal identifier "lan" "wan" "optX" ? The passing is verbatim obviously but the question is what you want to input and how you want to use it underneath.


Cheers,
Franco

April 10, 2026, 06:41:59 PM #4 Last Edit: April 10, 2026, 07:43:26 PM by drosophila
Quote from: franco on April 10, 2026, 09:44:43 AMYes, that's true for cron-visible actions (tagged with description: in the actions.conf file).  Also documented as such in the manual:
https://docs.opnsense.org/manual/settingsmenu.html#cron
That's my usual problem: it's all in the docs, but never where I look. For some reasons I only ever find the somewhat relevant pages through web searches or links in articles or even forum posts that I also find through web searches, not through the documentation index or its search. So, thanks for linking this! :) This is a general issue of mine and not restricted to OPNsense, so probably the documentation is OK.
Quote from: franco on April 10, 2026, 09:44:43 AMInstructions unclear: what does your script do and what do you want to pass? internal identifier "lan" "wan" "optX" ? The passing is verbatim obviously but the question is what you want to input and how you want to use it underneath.
I'd like to enter the assigned identifier (be that "wan" or "__WAN_IF__" or whatever) and have that auto-translated to the assigned interface ("re1" in this case) before being passed to the script.
So, AFAICS, exactly like the "Periodic interface reset", where the documentation you kindly linked says (identifier: Internal name of the interface as shown in assignments or overview page, e.g. "lan", "wan", "optX".). Does this mean that I can just put "wan" in there and it'll automagically be converted to the assigned interface? It seems the documented script does this translation internally, using php-internal variables though.

Currently, I've entered "re1" and my script also defaults to "re1" if nothing is given, but that is obviously going to break. For some reason, the script still goes into the default so it seems my passing still doesn't work.

The script and its corresponding action file posted at the very end of this thread. It would be nice if someone could point out what I'm missing with the parameter passing. It's logging the parameter $1 to /tmp and this file always comes up empty so I'm still missing something in the parameter passing.
As I really only need this singular parameter I don't think this should be affected by the issue reported on GH, but maybe I'm wrong and it ends up in $2 or even $0 for some reason?

BTW, if there is an internal variable for the assigned wan interface that I could use from /bin/sh, I'd just hardcode that in the script and wouldn't need the parameter at all. There doesn't seem to be anything in the environment variables though, at least I couldn't find anything.

BTW, the guy in this thread has entered "*/10" in the minutes field; the docs I found say that means "every 10 minutes", so there is no way of specifying sub-minute intervals?