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

    Running a python program in pfsense

    General pfSense Questions
    3
    3
    2.0k
    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

      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
      • DerelictD
        Derelict LAYER 8 Netgate
        last edited by

        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
        • jimpJ
          jimp Rebel Alliance Developer Netgate
          last edited by

          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
          • First post
            Last post
          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.