示例#1
0
def grep_files(args, all_logs):
    log('\n', args, False)
    if args.grep:
        if all_logs:
            all_logs.sort()
            grep_cmd = grep_command(args)
            log(
                colored('Running grep command ({0})\n'.format(grep_cmd),
                        'cyan'), args, False)
            for filename in all_logs:
                log(
                    colored(
                        get_timestamp_string(filename) + ' => ' + filename,
                        'cyan') + '\n', args, not args.show_file_info)
                content = subprocess.Popen(['cat', filename],
                                           stdout=subprocess.PIPE)
                if filename.endswith('.gz'):
                    zcat = subprocess.Popen('zcat',
                                            stdin=content.stdout,
                                            stdout=subprocess.PIPE)
                    grep = subprocess.Popen(grep_cmd,
                                            stdin=zcat.stdout,
                                            shell=True)
                else:
                    grep = subprocess.Popen(grep_cmd,
                                            stdin=content.stdout,
                                            shell=True)
                grep.communicate()
            log(colored('Finished grep, exiting', 'green') + '\n', args, False)
        else:
            sys.stderr.write(colored('No logs found\n', 'magenta'))
示例#2
0
def cat_files(args, all_logs):
    log('\n', args, False)
    if all_logs:
        all_logs.sort()
        for filename in all_logs:
            log(colored(get_timestamp_string(filename) + ' => ' + filename, 'cyan') + '\n', args, not args.show_file_info)
            if filename.endswith('.gz'):
                cat = subprocess.Popen(['cat', filename], stdout=subprocess.PIPE)
                content = subprocess.Popen(['zcat'], stdin=cat.stdout)
                content.communicate()
            else:
                cat = subprocess.Popen(['cat', filename])
                cat.communicate()
            sys.stdout.write('\n')
    else:
            log(colored('No log files found\n', 'magenta'), args, False)
示例#3
0
def grep_files(args, all_logs):
    log('\n', args, False)
    if args.grep:
        if all_logs:
            all_logs.sort()
            grep_cmd = grep_command(args)
            log(colored('Running grep command ({0})\n'.format(grep_cmd), 'cyan'), args, False)
            for filename in all_logs:
                log(colored(get_timestamp_string(filename) + ' => ' + filename, 'cyan') + '\n', args, not args.show_file_info)
                content = subprocess.Popen(['cat', filename], stdout=subprocess.PIPE)
                if filename.endswith('.gz'):
                    zcat = subprocess.Popen('zcat', stdin=content.stdout, stdout=subprocess.PIPE)
                    grep = subprocess.Popen(grep_cmd, stdin=zcat.stdout, shell=True)
                else:
                    grep = subprocess.Popen(grep_cmd, stdin=content.stdout, shell=True)
                grep.communicate()
            log(colored('Finished grep, exiting', 'green') + '\n', args, False)
        else:
            sys.stderr.write(colored('No logs found\n', 'magenta'))
示例#4
0
def cat_files(args, all_logs):
    log('\n', args, False)
    if all_logs:
        all_logs.sort()
        for filename in all_logs:
            log(
                colored(
                    get_timestamp_string(filename) + ' => ' + filename, 'cyan')
                + '\n', args, not args.show_file_info)
            if filename.endswith('.gz'):
                cat = subprocess.Popen(['cat', filename],
                                       stdout=subprocess.PIPE)
                content = subprocess.Popen(['zcat'], stdin=cat.stdout)
                content.communicate()
            else:
                cat = subprocess.Popen(['cat', filename])
                cat.communicate()
            sys.stdout.write('\n')
    else:
        log(colored('No log files found\n', 'magenta'), args, False)