快速定位想要查询的日志路径的方案 – Centos

系统+安全 Liemer_Lius 1100℃ 0评论

今天突然想到,如果我们配置的服务不少,容易记不住日志的位置,当然,做为运维,日志的位置是必须要记住的。可如果一时忘记的时候,再用find命令查找,或者查看配置文件(配置文件的位置也可能忘记哦,/偷笑),那就比较费时了。

这里,我想到一个比较好用的方法。

我们可以将所有服务器中的服务日志路径,编写入一个文件,写入所有服务的日志路径,例如:

# vim ~/tools/log_path.txt
mysql-err: /data/mysql/mysql-err
mysql: /usr/local/mysql/logs/mysql-log
nginx-err: /usr/local/nginx/logs/nginx.err
ngxin: /usr/local/nginx/logs/nginx.log
... ...
... ...

一旦有了新的服务,只要将这个文件丰富一下。

下面就做一个脚本,并建立别名:

# vim ~/find_log.sh
#!/bin/bash
# Find log automatically.
# Date: 2018-01-12
# Script Name: find_log.sh
# Author: Liemer_Lius
if [ $# -lt 1 ]; then
 echo "A service name should be given."
 exit 4
fi
if grep $1 ~/tools/log_path.txt &> /dev/null; then
 echo -e "\033[31mLogpath:\033[0m"
 grep --color=auto ^$1 ~/tools/log_path.txt
else
 echo "There is no information about the log you have given."
 exit 5
fi

建立别名:

# echo "alias findlog='/bin/bash ~/find_log.sh'" >> ~/.bashrc
# source .bashrc
# findlog mysql
Logpath:
mysql-err: /data/mysql/mysql-err
mysql: /usr/local/mysql/logs/mysql-log

 

转载请注明:liutianfeng.com » 快速定位想要查询的日志路径的方案 – Centos

喜欢 (0)

发表回复