New to Python and need some help [closed]
开发者_如何学C
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this questionGood day.
I'm after some help and probably jumping in the deepend here.
I'm trying to write a plugin that will check if services are on or of on a mac os x server. The plugin needs to be written in python and I have manage to create something that will give me result's, but I need some help in finishing it off.
import os
os.system("serveradmin status afp")
os.system("serveradmin status dhcp")
os.system("serveradmin status dirserv")
os.system("serveradmin status dns")
os.system("serveradmin status ftp")
So if save the following into test.py and then type: python test.py into terminal I get a result back.
The plugin that I am creating requires a class and a run(self) class method that returns a Python dictionary.
This is were I fall down. Could any one point me in the right direction.
Thanks
It'll be something along these lines.
class someclass:
def run(self):
return dict((svc, os.popen('serveradmin status ' + svc, 'r').read().strip())
for svc in ('afp', 'dhcp', 'dirserv', 'dns', 'ftp'))
精彩评论