I am trying to tail the files in a config file using python on mac
I am able to get the values from the config file but not able to open up child processes for the same
a sample config file has
[section1]
host_prefix = true
timestamp_prefix = true
[section2]
host = localhost
port = 1463
pids = /var/run/harvester
[files]
apache.access = /var/log/apache2/access.log
apache.errors = /var/log/apache2/errors.log
mail = /var/log/mail.log
mysql.log = /var/log/mysql.log
I am opening up the config file and trying to get the filepaths and I need to tail them in new child processes in separate terminals
#! /bin/env python
import StringIO
import os
import re
from multiprocessing import Process
COMMENT_CHAR = '#'
OPTION_CHAR = '='
def parse_config(filename):
options = {}
f = open(filename)
for line in f:
if COMMENT_CHAR in line:
line, comment = line.split(COMMENT_CHAR, 1)
if OPTION_CHAR in line:
option, value = line.split(OPTION_CHAR, 1)
option = option.strip()
value = value.strip()
options[option] = value
f.close()
return options
try:
f = open("/etc/harvest.conf", 'r')
print 'found'
options = parse_config('/etc/harvest.conf')
print options.values()
os.system('tail -f options.values')
except:
try:
f = open("/usr/local/etc/harvest.conf", 'r')
print 'found'
options = parse_config('/usr/local/etc/harvest.conf')
print options.values()
os.system('tail -f options.values')
except IOError:
print 'cannot find file'
the above code gives me all the values from the config file that includes ‘localhost’,’1463′
but I want only the paths from the file and need to tail them in separate child processes
Try ConfigParser. It can work with INI files.