#!/bin/bash

#. /etc/functions

# this shell is used for cli command "clear log"
# if the input parm $1 is "all" .then clear all the log files
# the $1 can also be the name of a particually file without the path,then this shell will only clear
# the given log file.

#/pica/config/pica.conf is the configure file of pica,we grep it to find the syslogd is 
#output to /var/log/message or /tmp/log/messages
# if pica.conf doesn't exist ,the use the default configure,the log file is /tmp/log/messages
# clear xorp_rtrmgr.log anyway
#> ${LOG_FILE}

if [ -f /pica/config/pica.conf ]
then
	TMP=`grep "local-file:" /pica/config/pica.conf | awk -F \" '{print $2}'`
    if [ x"$TMP" = x"disk" ]
    then
          LOG_FILE="var"
    else
          LOG_FILE="tmp"
    fi
else 
		LOG_FILE="tmp"
fi
# the $1 is all ,clear all the log files,otherwise clear only the given log file
if [ x"$1" = x"all" ] ; then 
    for file in /${LOG_FILE}/log/messages 
    do
        > $file
    done
else
    # TODO: deal with more than one files
    if [ -e /${LOG_FILE}/log/$1 ] ; then 
        > /${LOG_FILE}/log/$1
    else
        echo "No such log file: $1"
    fi
fi
sync

exit 0
