#!/usr/bin/env python
-- coding: UTF-8 --
import os
nginxLogPath = './nginx.log' phpLogPath = './php.log' phpFpmLogPath = './php-fpm.log' mysqlLogPath = './mysql.log'
def printMenu(): print("\033[21;32m ############# 欢迎使用日志系统 ##############\033[0m") print("\033[21;32m 1)输入1,访问nginx日志 \033[0m") print("\033[21;32m 2)输入2,访问php日志 \033[0m") print("\033[21;32m 3)输入3,访问php-fpm日志 \033[0m") print("\033[21;32m 4)输入4,访问mysql日志 \033[0m") print("\033[21;32m 5)输入5,查看各日志路径 \033[0m") print("\033[21;32m 6)输入6,查看各配置文件路径 \033[0m") print("\033[21;32m 7)输入7,查看相关命令 \033[0m") print("\033[21;32m 5)输入q退出 \033[0m") getNum = raw_input('>>') return getNum
def printLogPath(): print("/logs/www.ss.log") print("/logs/php.log") print("/logs/php-fpm.log") print("/logs/my.log") return
def printConf(): print("/elk.conf") print("/etc/php.conf") print("/etc/php-fpm.conf") print("/etc/my.conf") return
def printLog(num,tail_num): n = tail_num if (num == 1) : os.system("tail -%s %s"%(n,nginxLogPath)) elif (num == 2) : os.system("tail -%s %s"%(n,phpLogPath)) elif (num == 3) : os.system("tail -%s %s"%(n,phpFpmLogPath)) elif (num == 4) : os.system("tail -%s %s"%(n,mysqlLogPath)) elif (num == 5) : printLogPath() elif (num == 6) : printConf() return
while True: res = printMenu() if res == 'q': exit() num_list = res.split(' ') tail_num = 10
if not num_list[0].isdigit() : continue
if len(num_list) >=2 : if not num_list[1].isdigit() : continue else: tail_num = int(num_list[1])
num = int(num_list[0]) printLog(num,tail_num)