Simple question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bigodines

    #1

    Simple question

    Hi guys!

    I'm a complete newbie in Python and I'm trying to make a small software
    to watch my network. It will be a simple snmpget report for a specific
    machine.

    I would like to make a small program in python to be runed with
    crontrab that will store the whole output in a txt file. I know its not
    a big deal, but i've no background in python :)

    basically i would like to know how to:

    1 - execute a command in the server
    2 - write the whole output into a file.

    best regards,
    Matheus

  • bigodines

    #2
    Re: Simple question

    SOLVED,

    thanks for your time. :)


    bigodines wrote:[color=blue]
    > Hi guys!
    >
    > I'm a complete newbie in Python and I'm trying to make a small software
    > to watch my network. It will be a simple snmpget report for a specific
    > machine.
    >
    > I would like to make a small program in python to be runed with
    > crontrab that will store the whole output in a txt file. I know its not
    > a big deal, but i've no background in python :)
    >
    > basically i would like to know how to:
    >
    > 1 - execute a command in the server
    > 2 - write the whole output into a file.
    >
    > best regards,
    > Matheus[/color]

    Comment

    • Steve Holden

      #3
      Re: Simple question

      bigodines wrote:[color=blue]
      > Hi guys!
      >
      > I'm a complete newbie in Python and I'm trying to make a small software
      > to watch my network. It will be a simple snmpget report for a specific
      > machine.
      >
      > I would like to make a small program in python to be runed with
      > crontrab that will store the whole output in a txt file. I know its not
      > a big deal, but i've no background in python :)
      >
      > basically i would like to know how to:
      >
      > 1 - execute a command in the server[/color]

      The normal way would be using the command

      python script.py
      [color=blue]
      > 2 - write the whole output into a file.
      >[/color]
      Well, one way would simply be to use output redirection, such as

      python script.py > /tmp/file.txt

      Another alternative is to allow Python to open a file using

      f = open("some/file/name.txt", "w")

      and then use

      f.write(...)

      or

      print >> f, ...

      statements to send the output to the given file, finally closing it with

      f.close()

      The advantage of this latter method is that you can compute the filename
      (the first argument to the open() function) in Python if you want, using
      elements like the current date and time.

      regards
      Steve
      --
      Steve Holden +44 150 684 7255 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Love me, love my blog http://holdenweb.blogspot.com
      Recent Ramblings http://del.icio.us/steve.holden

      Comment

      Working...