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

Similar Threads

Simple Program 0
Non-Programmer Needs Help With Simple Program 3
Simple Javascript Inheritance Problem 0
New Member: Simple 'where to start' question. 0
Question 0
Question 1
Simple question 0
Register Question 0

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,283
Latest member
SherriP988

Latest Threads

Top