Simple question

B

bigodines

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
 
S

Steve Holden

bigodines said:
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

The normal way would be using the command

python script.py
2 - write the whole output into a file.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top