2014年04月23日 23:37:15

快捷查看日志的shell

作者: 
本文提供一个快捷查看日志的shell文件。
#!/bin/bash
#author:    Zjmainstay
#website:   http://zjmainstay.cn
#filename:  taillog

#usage: 
#first time: $path_to_this_shell/taillog.sh
#other time: $taillog  or $taillog 2014_04_15 for specified day log

#create quick command
LOG_PATH="/var/logs"
FILE_PATH=$0

pwd
FILE_DIR=`dirname $0`
if [ $FILE_DIR == '.' ]
then
    FILE_PATH=${FILE_DIR/'.'/~}
fi

#create bin dir if not exists
if [ ! -d ~/bin ]
then
    mkdir ~/bin
fi

#link current file to bin dir
if [ ! -f ~/bin/taillog ]   ## "~/bin/taillog" is wrong here
then
    ln -s $FILE_PATH ~/bin/taillog
fi

#tail log file if exists
if [ -z $1 ]
then
    dir=$(date +"%Y_%m_%d")
else
    dir=$1
fi

LOG_FILE=${LOG_PATH}/$dir.log
if [ -f $LOG_FILE ]
then
    tail -f $LOG_FILE
else
    echo "$LOG_FILE is not exists."
fi



未经同意禁止转载!
转载请附带本文原文地址:快捷查看日志的shell,首发自 Zjmainstay学习笔记
阅读( 4070 )
看完顺手点个赞呗:
(1 Vote)

1.PHP cURL群:PHP cURL高级技术
2.正则表达式群:专精正则表达式
3. QQ联系(加请说明):QQ联系博主(951086941)
4. 邮箱:zjmainstay@163.com
5. 打赏博主:

网站总访问量: