Reset state table using Cron

Started by dcol, June 23, 2023, 07:00:49 PM

Previous topic - Next topic
I have been unsuccessful trying to reset the state table using cron. All I get is 'returned exit status 127'
can anyone help with my code? Here is what I did

/usr/local/opnsense/service/conf/actions.d/actions_ResetST.conf

[start]
command:/usr/local/etc/rc.d/rstate.sh
parameters:%s
type:script
message:starting reset_state_table
description:Reset State Table


usr/local/etc/rc.d/rstate.sh

#!/bin/sh
pfctl -F states


Then ran 'service configd restart' in shell and setup the time in cron.

What am I doing wrong?
Thanks

1) You could probably remove '%s' (just leave 'parameters:' empty), since this has something to do with passing parameters, which you are not using here.
2) Because you are using a single command, it's a bit overkill to make a separate shell script for it. It would be simpler to do something like 'command:/sbin/pfctl -F states'.
In theory there is no difference between theory and practice. In practice there is.

I took your advice and using 'command:/sbin/pfctl -F states'.
No more error. The backend log shows reset started, but no log entry for what it did. Do I need to change something like script to script-output so I can see what the command did?

Yes, I think so, change 'type:script' to 'type:script_output' (with underscore).
In theory there is no difference between theory and practice. In practice there is.

I think that work, although the backend log shows it as an error as below.

2023-06-23T11:23:00-07:00   Informational   configd.py   message a61b4e69-fe65-43ed-9fdc-afb05ae76ab3 [] returned   
2023-06-23T11:23:00-07:00   Error   configd.py   [a61b4e69-fe65-43ed-9fdc-afb05ae76ab3] Script action stderr returned "b'280 states cleared'"   
2023-06-23T11:23:00-07:00   Notice   configd.py   [a61b4e69-fe65-43ed-9fdc-afb05ae76ab3] starting reset_state_table