def monitor(args):
    """ file monitor mode """
    filename = args.get('MDFILE')
    if not filename:
        print col('Need file argument', 2)
        raise SystemExit
    last_err = ''
    last_stat = 0
    while True:
        if not os.path.exists(filename):
            last_err = 'File %s not found. Will continue trying.' % filename
        else:
            try:
                stat = os.stat(filename)[8]
                if stat != last_stat:
                    parsed = run_args(args)
                    print parsed
                    last_stat = stat
                last_err = ''
            except Exception, ex:
                last_err = str(ex)
        if last_err:
            print 'Error: %s' % last_err
        sleep()
file monitor mode