CPUG: The Check Point User Group

Resources for the Check Point Community, by the Check Point Community.


First, I hope you're all well and staying safe.
Second, I want to give a "heads up" that you should see more activity here shortly, and maybe a few cosmetic changes.
I'll post more details to the "Announcements" forum soon, so be on the lookout. -E

 

Results 1 to 6 of 6

Thread: Trying to run Python script

  1. #1
    Join Date
    2014-11-23
    Posts
    50
    Rep Power
    6

    Default Trying to run Python script

    Hi

    I have a large number of host objects that need to be removed from my rule base (I am running GAIA R80.20).
    If I do this the traditional way then I need to view each object and find where itís used, and then remove the object from all the groups itís in, and then remove all the occurrences object in the security and NAT rules which takes a LONG time.
    I am trying to use a python script instead ( https://community.checkpoint.com/t5/...ect/td-p/38895 ), however when I try to run the file I get the following error:

    [Expert@man-server]# ./delete_host.py
    [-bash: ./delete_host.py: /bin/python^M: bad interpreter: No such file or directory

    Do you know why Iím getting this error? Do I need to install some sort of Python interpreter before I can run this file perhaps?

    Many thanks

  2. #2
    Join Date
    2006-04-27
    Location
    Twillight zone
    Posts
    1,010
    Rep Power
    16

    Default Re: Trying to run Python script

    do the :

    dos2unix delete_host.py


    Then try running your command again

  3. #3
    Join Date
    2007-03-30
    Location
    DFW, TX
    Posts
    327
    Rep Power
    14

    Default Re: Trying to run Python script

    To expand on this, the "^M" part of the error is a control character. Control-M is a carriage return.

    Different platforms encode line endings in different ways. Specifically, classic Mac OS used a carriage return, UNIX/Linux use a line feed, and Windows uses a carriage return and a line feed, because they think a terminal is a typewriter.

    On Linux, scripts generally start with a special line to indicate the interpreter. This line starts with #! and is commonly called "shebang". The characters from the exclamation point to the next line feed are the command which the shell should use to interpret the script.

    Since Windows puts a carriage return before the line feed, the script is telling the shell to run "/bin/python^M" instead of the proper "/bin/python". The dos2unix command abusharif mentioned exists to strip out the carriage returns from line endings.
    Zimmie

  4. #4
    Join Date
    2014-11-23
    Posts
    50
    Rep Power
    6

    Default Re: Trying to run Python script

    Thanks very much for your replies, that is interesting to know :)

    I am now getting the following message, I wondered if you'd seen this before?

    [Expert@x]# dos2unix delete_host.py
    dos2unix: converting file delete_host.py to Unix format ...
    [Expert@x]#
    [Expert@x]# ./delete_host.py
    Traceback (most recent call last):
    File "./delete_host.py", line 14, in <module>
    import rulebasecsv
    ImportError: No module named rulebasecsv
    [Expert@x#

  5. #5
    Join Date
    2007-03-30
    Location
    DFW, TX
    Posts
    327
    Rep Power
    14

    Default Re: Trying to run Python script

    Python has a concept of modules. A module provides functions and object types which Python by itself does not.

    Apparently this script requires one called "rulebasecsv", which isn't on the system where you are trying to run the script. I'm not familiar with this module, so you should probably ask about it wherever you got the script.
    Zimmie

  6. #6
    Join Date
    2014-11-23
    Posts
    50
    Rep Power
    6

    Default Re: Trying to run Python script

    one of our Python programming guys is having a look at it. I will let you know if he comes up with anything.

Similar Threads

  1. FW log export script
    By tsfstarr in forum SmartView Tracker
    Replies: 4
    Last Post: 2017-04-13, 05:42
  2. Script for mail
    By bingdude in forum R80
    Replies: 1
    Last Post: 2016-10-14, 09:39
  3. Startup Script
    By hasdou in forum Scripts and Tools
    Replies: 2
    Last Post: 2015-05-19, 11:39
  4. MDS log_rotate script
    By hansen68 in forum Provider-1 (Multi-Domain Management)
    Replies: 1
    Last Post: 2010-02-15, 11:35
  5. FTP backup script
    By IndyBoiler in forum Check Point Backup Procedures
    Replies: 8
    Last Post: 2008-01-24, 11:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •