Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Creating scripts

    Scheduled Pinned Locked Moved General pfSense Questions
    4 Posts 3 Posters 1.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bdf0506
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • H
        heper
        last edited by

        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.
        https://doc.pfsense.org/index.php/Using_the_PHP_pfSense_Shell

        1 Reply Last reply Reply Quote 0
        • B
          bdf0506
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • N
            NOYB
            last edited by

            Some potential locations might be…

            /etc/YourScriptsDir/...
            /usr/local/libexec/YourScriptsDir/...
            /YourScriptsDir/...

            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)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.