Hi I’m a beginner in Python and looking for help with a problem. I am writing a short sript to display:
1. a simple help message
2. the date, client machine name and file being accessed.
3. the number of times each file is accessed.
I’ve managed the first 2 parts but having trouble with the third. I think that I need to split the file name and increment it by 1, but I’ve struggled to find an easy way to do this. Any ideas?
Thanks
Paul37
Here’s my script so far:
#!/usr/bin/python
import sys, getopt, string
def Usage ():
print "ftpscan [-h][-c]"
sys.exit(0)
def scanner(name, function):
file = open(name,'r')
while 1:
line=file.readline()
if not line: break
function(line)
file.close
def processline(line):
words = string.split(line)
date = words[0:4]
client = words[6]
file = words[8]
day = words[0]
month = words[1]
date = words [2]
time = words[3]
year = words [4]
print day,month,date,time,year,client,file
try:
optlist, list = getopt.getopt(sys.argv[1:],'hc')
except getopt.GetoptError:
Usage()
sys.exit(2)
for opt in optlist:
print opt
if opt[0] == '-h':
print ' help '
sys.exit(0)
if opt[0] == '-c':
print "Under Construction"
sys.exit(0)
filename = 'ftplog.data'
scanner(filename,processline)