OPNsense Forum

Archive => 23.1 Legacy Series => Topic started by: dcol on June 23, 2023, 07:00:49 PM

Title: Reset state table using Cron
Post by: dcol on June 23, 2023, 07:00:49 PM
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
Title: Re: Reset state table using Cron
Post by: dinguz on June 23, 2023, 07:29:46 PM
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'.
Title: Re: Reset state table using Cron
Post by: dcol on June 23, 2023, 08:03:39 PM
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?
Title: Re: Reset state table using Cron
Post by: dinguz on June 23, 2023, 08:10:04 PM
Yes, I think so, change 'type:script' to 'type:script_output' (with underscore).
Title: Re: Reset state table using Cron
Post by: dcol on June 23, 2023, 08:25:44 PM
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