Hi guys,
I'm new to Python and have a ? that some of you can maby help me on. I'm using python 2.4 and running the script from a windows machine getting data from a linux machine. I have a script that returns information from the linux box to me ( cpu usage, free memory, ect). What I need help on is taking that information ( output) and put that information into a txt file. Is this a simple task? Any help will be appreciated and thanks for any and all help.
here is the source code im using to get the information
I'm new to Python and have a ? that some of you can maby help me on. I'm using python 2.4 and running the script from a windows machine getting data from a linux machine. I have a script that returns information from the linux box to me ( cpu usage, free memory, ect). What I need help on is taking that information ( output) and put that information into a txt file. Is this a simple task? Any help will be appreciated and thanks for any and all help.
here is the source code im using to get the information
Code:
import xmlrpclib
import getopt
import types
import sys
import exceptions
class _Method:
def __init__(self,send,name,*args):
self.__send = send
self.__name = name
self.__fun = getattr(send, name)
self.__args = args
def __getattr__(self, name):
return Method(self.__send, "%s.%s" % (self.__name, name))
def __call__(self, *args):
ret={}
for x in self.__args:
for y in x:
ret[y]=x[y]
for x in args:
for y in x:
ret[y]=x[y]
ack=self.__fun(ret)
if ack['Acknowledgement']['code'] != 200:
raise Exception('Error in ' + self.__name, ack)
return ack
class Connection:
def __getattr__(self, name):
return _Method(self.__xmlrpc,name,self.__auth)
def __init__(self, *args):
optlist, optargs = getopt.getopt(args, "u:p:")
self.username = 'administrator'
self.password = 'administrator'
for o,a in optlist:
if o == '-u':
self.username = a
if o == '-p':
self.password = a
if(len(optargs) < 1):
raise 'Usage: ' + sys.argv[0] + ' [-u username] [-p password] server'
self.server = optargs[0]
self.args = optargs[1:]
if not isinstance(self.server, types.StringTypes):
raise 'expected server name: ', optargs
self.__auth = {'Authorization':{'username':self.username,'password':self.password}}
self.__xmlrpc = xmlrpclib.Server("http://" + self.server + "/RPC2")
Comment