Using less as an error monitor when scripting or configuring

Miscellaneous tools
Post Reply
Message
Author
musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

Using less as an error monitor when scripting or configuring

#1 Post by musher0 »

Hello.

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.
Attachments
view-xerrs_log.jpg
From left to right: the ROX key-binding window, /tmp/xerrs.log displayed by the less
script above, and the script's own icon on the ROX backdrop.
(37.29 KiB) Downloaded 265 times
visionner-xerrs_log.sh.zip
Same script as above, as a zip archive. Please unzip in /root/my-applications/bin.
(1.63 KiB) Downloaded 254 times
Last edited by musher0 on Thu 29 Jan 2015, 06:42, edited 7 times in total.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Ah, when you're a comet in the outer sky, the silence can be deafening! :)
Still, 7 people have downloaded this little script! This muffles it a bit. :)

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#3 Post by Ted Dog »

less is more but nothing better than tail.. :wink:

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

Ted Dog wrote:less is more but nothing better than tail.. :wink:
Hi, Ted Dog.

But tail's only use is to cut and optionally save the bottom lines of a file, yes?
Can you display xerrs.log with it? I mean, to follow errors?

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#5 Post by Ted Dog »

That was a old Unix joke, with a hidden dirty message. :oops:

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#6 Post by musher0 »

Ted Dog wrote:That was a old Unix joke, with a hidden dirty message. :oops:
Missed the dirty joke, shucks, English not being my mother tongue... ;)

But seriously, I've seen tail used to optionally monitor the installation of ocamlbrew.
I suppose a similar function or script could be written to monitor the Puppy error log.
I thought you were suggesting something like that.

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#7 Post by musher0 »

Hello, all.

A member requested a *.pet archive by PM, so here it is ! Thanks to that member
for his request.

The MONACO.ttf mono font is Included, as well as a xerrs_log.desktop file to launch
this little script from the menu. (Should appear in Menu -> Utilities -> Development.)

Please note that the real "less" utility needs to be installed. It's at
:http://www.greenwoodsoftware.com/less. My first post above contains an
URL where you can download a *.pet archive of less-470, to install on your Puppy.

~~~~~~~~~~~
As to the key binding the member requested, there is unfortunately no easy way to
put one in a *.pet archive without destroying the PuppyPin at install time. You will
have to do it manually.

Here's how, but it's not complicated. It's a simple matter of editing two files.
Make sure to make a back-up of them before you start editing.

Open file /root/Choices/ROX-Filer/PuppyPin in your editor. Scroll to the bottom.
Add this line:

Code: Select all

  <icon x="320" y="960" label="xerrs_log">/root/my-applications/bin/visionner-xerrs_log.sh</icon>
just above the last line, the one that has the word

Code: Select all

</pinboard>
.
Don't touch anything else. Save that file.

Next, open file /root/.config/rox.sourceforge.net/ROX-Filer/globicons
Again go to the bottom, and insert these three lines

Code: Select all

  <rule match="/root/my-applications/bin/visionner-xerrs_log.sh">
    <icon>/usr/local/lib/X11/mini-icons/mini-x2.xpm</icon>
  </rule>
just before the last line, the one that reads

Code: Select all

</special-files>
Don't touch anything else. Once done, save the file and exit your text editor.

To see the result of your work, open a terminal, and type:

Code: Select all

cd /root/Choices/ROX-Filer
rox -p=$PWD/PuppyPin
or restart from the initial black console with

Code: Select all

xwin <your-window-manager>
Voilà, your xerrs_log script should now be available on the backdrop.
~~~~~~~~~~~

I hope that you will find this "xerss_log sh" script useful. Feedback welcome. BFN.

musher0
Attachments
xerrs_log-0.1.pet
(40.51 KiB) Downloaded 256 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#8 Post by musher0 »

Hello, people.

Here's where the xerrs_log script is located in the (ae)menu.
It's under Utilities->Programming or under Utilities->Developement (in some Puppies).
It shoudd be at the same place in the jwm menu.

I hope this helps you finding it. BFN.

musher0
Attachments
xerrs_log-entry-in-aemenu.jpg
Please forgive my French! ;)
(34.24 KiB) Downloaded 149 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#9 Post by musher0 »

Hello.

New development: you can either run the latest script above... OR...

its "cousin" (so to speak) here:
http://murga-linux.com/puppy/viewtopic. ... ost#826384
has become an "error" filter.

Don't worry, if your LANG parm in your Puppy is not set to some variant of "fr", the
script's contents will be displayed in English without you ever noticing!

Motivation: I couldn't find a script or configuration anywhere to filter out the so-called
"error messages" from X in xerrs.log that have nothing to do with real errors or errors
of my doing, so I wrote one myself!

These errors may originate from zigbert's PMusic ;), or from the Xorg people not
understanding utf-8 properly ;), etc., etc.

My own errors I try to take care of, but as a user I resent being blamed for other
people's errors and I thoroughly dislike people who try to pass just anomalies or
non-errors as errors.

So there: this filter script.

Enjoy! (Or not!) :)

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply