Creating scripts

  • Hello everyone! I am in the process of switching to pfSense from Tomato. I've been using Tomato for years, and have many various scripts there that I need to port over before I officially make the cutover to pfsense. Two questions about this.

    (1) Where is the best place to store scripts that I want a cron job to run? I've already installed the cron package, but unsure of where to place these scripts. There are some that will run at startup, and others that will run via cron. I'd like them to be in a location where it will persist an upgrade, if possible.

    (2) Is there an easy way to call a variable such as the WAN IP or the WAN gateway? With Tomato, you can make a quick call the nvram to grab values that you need, but I haven't been able to find an easy way to do that. So for example if I want to get the WAN gateway, in Tomato I can do "nvram get wan_gateway", but in pfsense I am thinking I'll likely need to do something a little more complex like "netstat -r | grep default | awk '{print $2}'"… or is there a better way to get things like this?

    Thanks all.

  • perhaps you should explain, what you intend todo with these 'scripts'.

    almost everything is available through the developer-shell & is most likely the way to go.

  • They are shell scripts. For example, with Tomato I have a script that was monitoring my ISP connection, it was simply pinging a server, and writing a character to a file to indicate a success or failure. Then at midnight, it would wrap up the script, and insert the results into a mysql database that sits on another server.

    I can replicate the functionality easily, but where is the proper location to place something like that, call it via cron, and have it persist an upgrade? I wonder if i am better off installing optware or something to the like.

  • Some potential locations might be…


    Typically it's been my experience that non pfSense files don't seem to be overwritten or removed by updates.

    Don't use /var/... if nano install or RAM disk is ever enabled.  It will be wiped out.  Potentially even with just a reboot.

    I'm sure the WAN IP could probably be obtained via a function call somewhere.  But the address stored in /var/db/wan_ip may suffice for your needs.
    (the file name may be different if not using the default WAN interface name)

Log in to reply