B
Brown, Rodrick
I recently started playing with Python about 3 days now (Ex Perl guy) and wanted some input on style and structure of what I'm doing before I really start picking up some bad habits here is a simple test tool I wrote to validate home dirs on my system.
Please evaluate and let me know what could have been done better. Once again this is really my first time using python.
$ ./homedir_exists.py root mqm pcap
root successful!
Directory: /var/arpwatch not found!
pcap successful!
mqm successful!
$ cat homedir_exists.py
#!/usr/bin/env python
import sys, os
from re import match
userlist = []
filename = '/etc/passwd'
for user in sys.argv[1:]:
userlist.append(user)
try:
fh = open(filename)
except IOError:
print "No such filename: %s" % (filename)
def checkDir(username):
data = fh.readlines()
for line in data:
for user in username:
if match(user,line):
s = line.split(':')
if not os.path.isdir(s[5]):
print "Directory: %s not found!" % (s[5])
print s[0] + " successful!"
checkDir(userlist)
Please evaluate and let me know what could have been done better. Once again this is really my first time using python.
$ ./homedir_exists.py root mqm pcap
root successful!
Directory: /var/arpwatch not found!
pcap successful!
mqm successful!
$ cat homedir_exists.py
#!/usr/bin/env python
import sys, os
from re import match
userlist = []
filename = '/etc/passwd'
for user in sys.argv[1:]:
userlist.append(user)
try:
fh = open(filename)
except IOError:
print "No such filename: %s" % (filename)
def checkDir(username):
data = fh.readlines()
for line in data:
for user in username:
if match(user,line):
s = line.split(':')
if not os.path.isdir(s[5]):
print "Directory: %s not found!" % (s[5])
print s[0] + " successful!"
checkDir(userlist)