[SOLVED] Recommended location for a custom script for cron?

Started by epoch, August 05, 2017, 05:29:34 PM

Previous topic - Next topic
Hi.
I need to put an APU2C4 in double-nat mode (simpler and safer) behind some non-descript DSL box: box LAN IP 192.168.255.1, APU WAN IP 192.168.255.254, APU LAN IP 192.168.1.1

I want to run every services from OPNsense and the APU, and this includes OpenVPN for which I need a well-known address. The DSL box has a floating IP address.
I've looked at the dyndns plugin, but this one wants to monitor an interface that is on the LAN, so it won't do.
Instead I've read here a discussion about running a script via cron. This looks fine to me.

The script I would run is dnsactual.sh, I haven't tried it yet but it looks simple enough.
I have 2 questions :
- Where should I put that snippet on the local disk, so that it doesn't interfere with OPNsense but doesn't get wiped out at the first upgrade?
- In System>Cron I see a nice GUI but I don't see how to input a custom script. If I use the crontab facility from the command-line, will that resist an update/upgrade?

Thanks in advance. 17.7 looks pretty good so far!

I don't know about 'recommended' but I've put a script in /usr/home for a regular cron job that I run.
Regards


Bill

Hi epoch,

This is for start, early start and stop scripts:

https://docs.opnsense.org/development/backend/autorun.html

For cron jobs you can add a configd description file:

https://docs.opnsense.org/development/backend/configd.html

When you set the "description: My cron job" in the command settings, it will show up on the cron page for use.

All of these will be kept on updates / reboot. The only thing that could eventually happen is that somebody added a script with the same name so that will be overwritten. If you choose a "good name" (as in unique) that is very unlikely to happen. :)


Cheers,
Franco


August 05, 2017, 08:55:40 PM #4 Last Edit: August 05, 2017, 10:09:50 PM by epoch
So, this is what I did for FreeDNS.afraid.org:

/usr/local/opnsense/service/conf/actions.d/actions_freednsupdate.conf
[start]
command:/usr/home/freednsupdate.sh
parameters:%s
type:script
description:Check/update public IP on freedns.afraid.org
message:Updating public IP on freedns.afraid.org


/usr/home/freednsupdate.sh:
#!/bin/sh
CURL='/usr/local/bin/curl'
FREEDNS_URL='http://freedns.afraid.org/dynamic/update.php'
TOKEN="$1"

[ -z "$TOKEN" ] && exit
RANDOMIZE=`/usr/bin/jot -r 1 0 90`
(sleep $RANDOMIZE; $CURL "$FREEDNS_URL?$TOKEN" >/dev/null 2>&1 &)
exit 0

The script is very simple, the upstream update.php code does all the job and updates the IP when needed.
The RANDOMIZE thing is just here to push execution by a few seconds/minutes. It looks like FreeDNS might appreciate the attention.
EDIT: looks like there is a timeout in OPNSense, I've reduced the max induced delay to 90 secs (from 255).

Then I created a cron entry with the web UI. I've set it to run at 7 and 37 minutes every hour, chose the new command "Check/update public IP on freedns.afraid.org", and pasted my FreeDNS token as parameter.
Runs a treat.

Thanks again.

Yay, cool, marking this solved. 8)

PS: FreeDNS bug reports are welcome here https://github.com/opnsense/core/issues