OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 18.7 Legacy Series »
  • Cron job - Reset states- How?
« previous next »
  • Print
Pages: [1]

Author Topic: Cron job - Reset states- How?  (Read 6030 times)

chemlud

  • Hero Member
  • *****
  • Posts: 2040
  • Karma: 93
    • View Profile
Cron job - Reset states- How?
« on: December 20, 2018, 03:19:23 pm »
Hi again!

From time to time I have to reset the states with a simple

Code: [Select]
/sbin/pfctl -F state
via Cron.

However, I don's see any "free text" option for Cron under "System"-"Settings"-"Cron".

Is it possible to create an arbitrary Cron job and switch the <command> in the config.xml to make this work?
Logged
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

chemlud

  • Hero Member
  • *****
  • Posts: 2040
  • Karma: 93
    • View Profile
Re: Cron job - Reset states- How?
« Reply #1 on: December 24, 2018, 09:57:10 am »
Any help on that highly appreciated!
Logged
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

chemlud

  • Hero Member
  • *****
  • Posts: 2040
  • Karma: 93
    • View Profile
Re: Cron job - Reset states- How?
« Reply #2 on: December 28, 2018, 10:23:45 am »
Is there no way to create a custom cron job? Maybe from command line?
Logged
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

marjohn56

  • Hero Member
  • *****
  • Posts: 1676
  • Karma: 168
    • View Profile
Re: Cron job - Reset states- How?
« Reply #3 on: December 28, 2018, 10:50:32 am »
You need to create an entry for the job for configd, it then creates the cron job,


Have a look here.


http://kb.unixservertech.com/other/networking/opnsense/cron-jobs
Logged
OPNsense 21.7 - Qotom Q355G4 - ISP - Community Fibre 1Gbps.

Team Rebellion Member - If we've helped you remember to applaud

chemlud

  • Hero Member
  • *****
  • Posts: 2040
  • Karma: 93
    • View Profile
Re: Cron job - Reset states- How?
« Reply #4 on: December 28, 2018, 01:37:14 pm »
OK, many thanks, something to start with. Will the basic command

Code: [Select]
/sbin/pfctl -F state
work for OPNsense, as it comes from the other side of the sense universe?

Is nano present on OPNsense by default or how to "create a file" in the respective directory...

There really is no simple way to create a Cron job with a custom command? Really strange...

Many thanks in advance!
« Last Edit: December 28, 2018, 01:41:54 pm by chemlud »
Logged
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

marjohn56

  • Hero Member
  • *****
  • Posts: 1676
  • Karma: 168
    • View Profile
Re: Cron job - Reset states- How?
« Reply #5 on: December 28, 2018, 04:15:17 pm »
Quote from: chemlud on December 28, 2018, 01:37:14 pm
OK, many thanks, something to start with. Will the basic command

Code: [Select]
/sbin/pfctl -F state
work for OPNsense, as it comes from the other side of the sense universe?

Is nano present on OPNsense by default or how to "create a file" in the respective directory...

There really is no simple way to create a Cron job with a custom command? Really strange...

Many thanks in advance!


No it wont work, or should I say 'I doubt it will work'. It's all to do with security I suspect. It's really very very easy. Firstly, you need to create a conf file for your cron event. Here's one I use for ping check. It runs every ten minutes and if if fails continuously then it will reboot opnsense.


Code: [Select]
[load]
command:/usr/local/sbin/ping_check.sh
parameters:
type:script
message:starting ping check
description:ping_check

So you could just try using your command in the conf file, command and params, however, you may prefer to create a shell script and call that as I have done above.

Either way, once all is in place issue the command 'service configd restart' in the shell.

Now go to System->Settings-Cron and add your new entry, you should find your function is now listed in the drop down when you add a new job.
Logged
OPNsense 21.7 - Qotom Q355G4 - ISP - Community Fibre 1Gbps.

Team Rebellion Member - If we've helped you remember to applaud

chemlud

  • Hero Member
  • *****
  • Posts: 2040
  • Karma: 93
    • View Profile
Re: Cron job - Reset states- How?
« Reply #6 on: December 28, 2018, 05:08:49 pm »
...i'm logged in via SSH, but how to create/edit a file? nano is not in place, which editor is there (hopefully not vi....)

I'm a little lost....

PS: found libedit in the Packages, but this seems the same/more pain than vi at first sight... is there a simple editor available?
« Last Edit: December 28, 2018, 05:14:52 pm by chemlud »
Logged
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

fabian

  • Hero Member
  • *****
  • Posts: 2768
  • Karma: 199
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: Cron job - Reset states- How?
« Reply #7 on: December 28, 2018, 05:20:50 pm »
you can install vim (vim-lite) and emacs (emacs-nox) via pkg (both are in the repository). But you can also upload the file using sftp.
Logged

GDixon

  • Jr. Member
  • **
  • Posts: 98
  • Karma: 4
    • View Profile
Re: Cron job - Reset states- How?
« Reply #8 on: December 28, 2018, 05:39:17 pm »
I like nano also and had to use pkg add .  It works well.
Logged

chemlud

  • Hero Member
  • *****
  • Posts: 2040
  • Karma: 93
    • View Profile
Re: Cron job - Reset states- How?
« Reply #9 on: December 28, 2018, 05:55:16 pm »
I used vi now (copy&paste :-D) and created:

Code: [Select]
[load]
command:/sbin/pfctl -F state
parameters:
type:script
message:kill all states
description: kill_states

could establish a Cron job afterwards, but apparently the states are not killed... What's wrong here?

PS: Have to correct me, apparently the states are killed now, dunno why it didn't work first time... :-)
« Last Edit: December 28, 2018, 06:00:43 pm by chemlud »
Logged
kind regards
chemlud
____
"The price of reliability is the pursuit of the utmost simplicity."
C.A.R. Hoare

marjohn56

  • Hero Member
  • *****
  • Posts: 1676
  • Karma: 168
    • View Profile
Re: Cron job - Reset states- How?
« Reply #10 on: December 28, 2018, 11:54:25 pm »
Quote from: chemlud on December 28, 2018, 05:08:49 pm
...i'm logged in via SSH, but how to create/edit a file? nano is not in place, which editor is there (hopefully not vi....)

I'm a little lost....

PS: found libedit in the Packages, but this seems the same/more pain than vi at first sight... is there a simple editor available?


Simples... I use windows, therefore I create the file using notepad++ - remember to set end of line to Unix style, then I use WinSCP to transfer... sooo easy.
Logged
OPNsense 21.7 - Qotom Q355G4 - ISP - Community Fibre 1Gbps.

Team Rebellion Member - If we've helped you remember to applaud

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 18.7 Legacy Series »
  • Cron job - Reset states- How?
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2023 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2