#!/bin/bash # Name: Statique Littérateur # Type: Logs Manager # file: manage_logs # Folder: /var/lib/stl/scripts/ # By echolib (XMPP: im@echolib.re) # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #------------ # funny stats #------------ # lines: 156 # functions: 3 #----------------------------------------------------------------------- #********************************************************************** #====================================================================== # Manage Arguments #====================================================================== log__OPTIONS() { ! [[ "$2" ]] && article_log="stl.log" while test "$2" do case "$2" in *.log) article_log=`basename "$2"` ;; *".stl") unset article_log article__hash "$2" ;; clean) log_clean=true [[ $from_stl || $from_id ]] || article_log="stl.log" ;; all) [[ $log_clean ]] || continue unset articl_log rm -f /var/log/stl/*.log 2>/dev/null echo "# All logs cleaned" exit ;; *) noarg "$2" "Use: (ARTICLE) (+ clean)" ;; esac shift done ! [[ -f "$stl_dir_log/$article_log" ]] \ && echo "# No logs yet, for this article" \ && exit if [[ $log_clean ]];then rm -f "$stl_dir_log/$article_log" && \ echo "# Logs cleaned: $stl_dir_log/$article_log" exit else logs__print "$stl_dir_log/$article_log" fi } #====================================================================== # Add to log file $stl_file_log #====================================================================== log__add() { case "$1" in -i) log_f1="$stl_log_i";CL=${NC} ;; -w) log_f1="$stl_log_w";CL=${CY};stl_waring=true ;; -e) log_f1="$stl_log_e";CL=${CR};stl_error=true ;; *) log_f1="$1" ;; esac case "$2" in -C) log_f2="Check" ;; -M) log_f2="WIP" ;; -W) log_f2="WWW" ;; -S) log_f2="Sidebar" ;; -db) log_f2="Database" ;; *) log_f2="$2" esac case "$3" in -Mti) log_f3="title:" ;; -Mab) log_f3="about:" ;; -Mau) log_f3="author:" ;; -Mta) log_f3="tags:" ;; -Mim) log_f3="image:" ;; -Mda) log_f3="date:" ;; -Mbr) log_f3="brut:" ;; -Mpc) log_f3="code:" ;; -Mlf) log_f3="file:" ;; -Mlt) log_f3="link:" ;; -M) log_f3="Metas" ;; -A) log_f3="Article" ;; -S) log_f3="Stats" ;; -rs) log_f3="Publish" ;; -rm) log_f3="Remove" ;; -W) log_f3="Write" ;; *) log_f3="$3" esac log_f4="$4" # Maube to consider later... #f4_l=${#log_f4} #log_sp=$(( 40 - f4_l )) #echo "> f4_l=$f4_l ; log_sp=$log_sp" printf "%b%s%s%s%s%s%s%s%b\n" \ "${CL}" \ "`date +%F' '%T`│" \ "$domain_name│" \ "$log_f1│" \ "$log_f2│" \ "$log_f3│" \ "$log_f4│" \ "$this_article│" \ "${NC}" \ >> "$stl_file_last_log" printf "%b%s%s%s%s%s%s%s%b\n" \ "${CL}" \ "`date +%F' '%T`│" \ "$domain_name│" \ "$log_f1│" \ "$log_f2│" \ "$log_f3│" \ "$log_f4│" \ "$this_article│" \ "${NC}" \ >> "$stl_dir_log/$article_id.log" # Restore var this_article="$this_article_bkp" } #====================================================================== # Show logs by column # $1: file #====================================================================== logs__print() { [[ -f "$1" ]] || exit 0 cat "$1" | column -t -s'│' -o' ' #cat "$1" | column -t -s$'\t' -o' ' }