manage_server: Add new command to view log remotely
This commit is contained in:
parent
d7686f68c0
commit
ba75c5c8fd
2 changed files with 145 additions and 32 deletions
67
process/view_log.sh
Normal file
67
process/view_log.sh
Normal file
|
@ -0,0 +1,67 @@
|
|||
#! /bin/sh
|
||||
|
||||
cd `dirname $0`/..
|
||||
|
||||
UN=$1
|
||||
if [ "$1" = "full" ]
|
||||
then
|
||||
CMD=cat
|
||||
shift
|
||||
elif echo "$1" | grep -e '^-' > /dev/null
|
||||
then
|
||||
CMD="tail -n `echo $1 | cut -d '-' -f 2-`"
|
||||
shift
|
||||
else
|
||||
CMD="tail -n 50"
|
||||
fi
|
||||
|
||||
TMP=`mktemp`
|
||||
|
||||
DIRS="./"
|
||||
if [ -d "/var/log/hooks/" ]
|
||||
then
|
||||
DIRS="$DIRS /var/log/hooks/"
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
|
||||
for D in $DIRS
|
||||
do
|
||||
for I in `find "$D" -name '*.log'`
|
||||
do
|
||||
/bin/echo -e "`dirname ${I#$D}`/\e[1m`basename $I`\e[0m"
|
||||
done
|
||||
done
|
||||
|
||||
else
|
||||
|
||||
LIST=`mktemp`
|
||||
|
||||
find $DIRS -name '*.log' > $LIST
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
|
||||
NB=`grep "/$1" "$LIST" | wc -l`
|
||||
if [ $NB = 1 ]
|
||||
then
|
||||
$CMD `grep "/$1" "$LIST"`
|
||||
echo
|
||||
elif [ $NB -gt 1 ]
|
||||
then
|
||||
echo "Too much matching file for '$1':"
|
||||
for I in `grep "$1" "$LIST" | sed -E 's#^./##'`
|
||||
do
|
||||
/bin/echo -e "`dirname $I`/\e[1m`basename $I`\e[0m"
|
||||
done
|
||||
else
|
||||
echo "Unable to find '$1' log file"
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
|
||||
done
|
||||
|
||||
rm -rf "$LIST";
|
||||
fi
|
Reference in a new issue