fixed bug in history loging func

This commit is contained in:
Serghey Rodin 2012-09-27 11:07:55 +03:00
commit 779b9cf521
2 changed files with 14 additions and 16 deletions

View file

@ -69,7 +69,11 @@ chmod 644 $VESTA/data/packages/$package.pkg
#----------------------------------------------------------#
# Logging
log_history "added user package $package" '' 'admin'
if [ "$rewrite" != 'yes' ]; then
log_history "added user package $package" '' 'admin'
else
log_history "updated user package $package" '' 'admin'
fi
log_event "$OK" "$EVENT"
exit

View file

@ -59,25 +59,19 @@ log_event() {
log_history() {
cmd=$1
undo=${2-no}
log_user="$3"
log_user=${3-$user}
log=$VESTA/data/users/$log_user/history.log
if [ -z "$log_user" ]; then
log_user="$user"
touch $log
if [ '99' -lt "$(wc -l $log |cut -f 1 -d ' ')" ]; then
tail -n 99 $log > $log.moved
mv -f $log.moved $log
chmod 660 $log
fi
touch $USER_DATA/history.log
if [ '99' -lt "$(wc -l $USER_DATA/history.log |cut -f 1 -d ' ')" ]; then
tail -n 99 $USER_DATA/history.log > $USER_DATA/history.log.mv
mv -f $USER_DATA/history.log.mv $USER_DATA/history.log
chmod 660 $USER_DATA/history.log
fi
curr_str=$(grep "ID=" $VESTA/data/users/$log_user/history.log |\
cut -f 2 -d \' | sort -n | tail -n1)
curr_str=$(grep "ID=" $log | cut -f 2 -d \' | sort -n | tail -n1)
id="$((curr_str +1))"
HISTORY="ID='$id' DATE='$DATE' TIME='$TIME' CMD='$cmd' UNDO='$undo'"
echo "$HISTORY" >> $VESTA/data/users/$log_user/history.log
echo "ID='$id' DATE='$DATE' TIME='$TIME' CMD='$cmd' UNDO='$undo'" >> $log
}
# Argument list checker