This came about because I was tired of repeatedly going to folder /tmp and loading
xerrs.log in the text editor. Besides, xerrs.log is not an editable file; actually, you can,
but it creates trouble! (Explained below in the paragraph that starts with "Finally".)
This script saves me a lot of clicking -- and time, actually. It also displays the line
count and the size. If there are more than 70-72 lines, I immediately know something
is going wrong.
This script acts as a three-way switch: on - warning - off. I introduced the "warning"
because at times, when I write bash scripts, I have a lot of windows opened on my
screen and they hide the error log. So the "warning" step reminds me that I have
the xerrs.log open already.
The regular "less" way of closing a less display still goes, too: just hit the "q" key !!
(Or the "x" at the top right corner of the window!)
Finally, it doesn't touch the actual xerrs.log. My solution was initially responding to
a screen formatting concern, I needed a way to bring attention to the end of the
file. And then I realized that being unable to edit the actual file was a good thing.
(X is fussy that way: if you edit the xerrs.log file, it'll stop taking in errors. And you
need an active error log when you develop. )
As you can see on the illustration below, I've put a ROX icon on the screen. I've
coupled it with a very non standard key combo: CTRL+KEYPAD-minus. I can't miss
it (really opposite corners of the keyboard), and I've never seen a program use it.
(To do a key binding on the ROX backdrop or on a ROX panel, right-click on the
icon, and then click edit. Then you see a long button with "keyboard shortcut" on
top of it. Open that and then type the keyboard keys you want to associate with
that script or program. Once satisfied, click "ok", and you're done. Next time, you'll
be able to open your scipts or program with the new key combo you have just
defined. -- Please note: if a ROX panel, for your key combo to be active, the icon it
is associated with must be in the panel on screen.)
Nothing much in the way of dependencies:
* all Puppyists have urxvt on their system, right? (NOT rxvt)
* the less 470 installed (from http://murga-linux.com/puppy/viewtopic. ... ost#815558)
* the Monaco font (from http://www.ffonts.net/MONACO.font. There are
many others on the web, but this is the one I know works.)
If you need help with my # comments in French in the script, just holler, I'll
translate! But they should be obvious from the context, I think.
Enjoy!
~~~~~~~~~
EDIT NOTES, 15-01-25 --
* If you prefer a pet package, please go down to:
http://murga-linux.com/puppy/viewtopic. ... ost#823711
* I am enclosing a slightly more polished version of the script; also contains English
translation of most comments.
EDIT, 15-01-28 -- Replaced the "three waves" ("~~~") with a "rarer" flag: "¬¤¬",
at lines 50 and 53. Working with the script I realized that a "~~~" flag may be
confusing for the less pager, because some programmers use the "wave" in point
form texts, for example.
* Today I also corrected two double quotes typos that were on each side of the
flag. Sorry about that.
* Finally, I partly rewrote the explanation about NOT using the "exit" command at
the bottom of the script, with a view to making it more understandable.
~~~~~~~~~
Code: Select all
#!/bin/sh
# /root/my-applications/bin/visionner-xerrs_log.sh
# (c) musher0, 14-16 janvier 2015; rév. 24 janv. 2015.
#
# But : surveiller l'évolution des erreurs sur son Puppy sans se fatiguer ! /
# Goal: monitor evolution of errors without sweat on your Puppy!
#
# Utile pour : développeurs et utilisateurs avancés. /
# Useful for: developers and advanced users.
####
# Fonctions
function splache {
# message et couleurs
[ "${LANG:0:2}" = "fr" ] && TXTMSG="Le fichier est déjà affiché." || TXTMSG="The file is already displayed."
CLR="bd black -bg sienna1 -fg white"
# affichage
yaf-splash -margin 30 -bw 15 -$CLR -placement center -font Monaco -fontsize 11 -timeout 4 -outline 0 -text "$TXTMSG" &
}
function xerrslog {
# préparation
[ -f /tmp/xerrs.less ] && rm -f /tmp/xerrs.less
# choix de l'éditeur
[ `which joe` ] && export EDITOR=/root/my-applications/bin/joel.sh &>/dev/null || export EDITOR=/usr/local/bin/defaulttexteditor
# Note : la COPIE du registre d'erreurs sera chargée en tapant 'v'.
# param. urxvt
Geom="g 84x25-320-85"
COLR="bg "#2F4A3A" -fg white -bd OrangeRed3 -cr "#542214" -tr -tint AntiqueWhite4 -sh 101" # transparence
FNT="fn xft:Monaco:pixelsize=13:antialias=true:autohint=true"
CADR="b 20 +sb +st +tcw -sbt 14 -bc"
[ ${LANG:0:2} = "fr" ] && lign="lignes" || lign="lines"
NLIGN="`wc -l /tmp/xerrs.log | awk -v l="$lign" '{ print $2" -- ("$1" "l }'`"
poids="`ls -logh /tmp/xerrs.log | awk '{ print $3 }'`"
# messages pour less
AIDE="[ 'q',quitter 'h',aide 'g',début 'G',fin 'u',haut 'd', bas]"
HELP=" [ 'q',quit 'h',help 'g',top 'G',end 'u',up 'd',down ]"
[ ${LANG:0:2} = "fr" ] && INFO="$AIDE" || INFO="$HELP"
# param. less
PARAMLESS="C -b 2 -J -j 65 -w -s -x 3 -z 72 -N"
# copie du fichier avec ajout pour aller à la fin directement.
# De toute façon, xerrs.log est un fichier d'information NON éditable.
cat /tmp/xerrs.log > /tmp/xerrs.less
echo "¬¤¬" >> /tmp/xerrs.less
# affichage
urxvt -$FNT -$CADR -T "$NLIGN; $poids) --" -$COLR -$Geom &>/dev/null -e less -$PARAMLESS -p "¬¤¬" -P " $INFO " -~ /tmp/xerrs.less
# nettoyage
rm -f /tmp/xerrs.less
}
## Mise en action (commutateur à trois positions)
if [ "`ps | tr -s ' ' | awk '$4=="less" && $NF ~ /xerrs/'`" = "" ];then
xerrslog &>/dev/null # Ouvrir
else
if [ -f /tmp/xerrslog.vu ];then
kill "`ps | awk '$4=="urxvt" && $NF ~ /xerrs/ { print $1 }'`" &>/dev/null
rm -f /tmp/xerrslog.vu # Fermer *
else
splache
echo vu > /tmp/xerrslog.vu # Avertir
fi
fi
# * #### À propos de la commande "exit" #### (English below)
# Pas besoin de forcer la sortie (en utilisant "exit"). Si la syntaxe de bash est
# respectée, une fois les conditions satisfaites, le script se fermera de lui-même. /
# * #### About the "exit" command #### (Français ci-dessus)
# No need to force an exit (by using "exit"). If the bash syntax is respected, the
# script will exit by itself once the conditions are satisfied.