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

Running a python program in pfsense

Scheduled Pinned Locked Moved General pfSense Questions
3 Posts 3 Posters 2.0k 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.
  • C
    CouldntMakeUpOne
    last edited by Mar 11, 2019, 3:50 PM

    Hi, new to pfsense and networking stuff. I'm trying to run a python script but just testing pfsense out by running a normal program first.

    So, I went into the shell

    1. Made a program called try.py using "touch try.py"
    2. Edited the program using vi and putting print("hi")
    3. Tried to run it using "./try.py"
      but it doesn't work. I'm using 2.4.4 and it should have python 2.7 installed right?
      it gives the error of "./try.py: 1: Syntax error: word unexpected (expecting ")")

    Am I doing something wrong?

    1 Reply Last reply Reply Quote 0
    • D
      Derelict LAYER 8 Netgate
      last edited by Mar 11, 2019, 3:57 PM

      python try.py

      Look up what a shebang is.

      Chattanooga, Tennessee, USA
      A comprehensive network diagram is worth 10,000 words and 15 conference calls.
      DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
      Do Not Chat For Help! NO_WAN_EGRESS(TM)

      1 Reply Last reply Reply Quote 0
      • J
        jimp Rebel Alliance Developer Netgate
        last edited by Mar 11, 2019, 7:29 PM

        On pfSense 2.4.4, python 2.7 is available as python2.7. So your try.py could run one of a couple ways:

        1. Run the script using the correct binary:
          python2.7 try.py
        2. Edit try.py, change the first line to reflect the correct python binary, which will allow it to run with ./try.py
          #!/usr/bin/env python2.7
        3. Make a symlink so you can invoke python 2.7 as python
          ln -s /usr/local/bin/python2.7 /usr/local/bin/python

        Note that in the future when python versions change, you would need to update whichever method you choose to point to the new binary, such as python3.6.

        Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        1 Reply Last reply Reply Quote 1
        3 out of 3
        • First post
          3/3
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
          This community forum collects and processes your personal information.
          consent.not_received