Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 14 Dec 2019, 02:37
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Using less as an error monitor when scripting or configuring
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Sat 17 Jan 2015, 18:14    Post subject:  Using less as an error monitor when scripting or configuring
Subject description: Check errors effortlessly -- for developers and advanced users
 

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! Sad (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) Smile
* the less 470 installed (from http://murga-linux.com/puppy/viewtopic.php?p=815558&sort=lastpost#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.php?p=823711&sort=lastpost#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:
#!/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.
view-xerrs_log.jpg
 Description   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.
 Filesize   37.29 KB
 Viewed   261 Time(s)

view-xerrs_log.jpg

visionner-xerrs_log.sh.zip
Description  Same script as above, as a zip archive. Please unzip in /root/my-applications/bin.
zip

 Download 
Filename  visionner-xerrs_log.sh.zip 
Filesize  1.63 KB 
Downloaded  194 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)

Last edited by musher0 on Thu 29 Jan 2015, 02:42; edited 7 times in total
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Wed 21 Jan 2015, 15:41    Post subject:  

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

BFN.

musher0

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
Ted Dog


Joined: 13 Sep 2005
Posts: 4013
Location: Heart of Texas

PostPosted: Wed 21 Jan 2015, 17:18    Post subject:  

less is more but nothing better than tail.. Wink
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Wed 21 Jan 2015, 18:17    Post subject:  

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
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
Ted Dog


Joined: 13 Sep 2005
Posts: 4013
Location: Heart of Texas

PostPosted: Wed 21 Jan 2015, 21:33    Post subject:  

That was a old Unix joke, with a hidden dirty message. Embarassed
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Thu 22 Jan 2015, 15:51    Post subject:  

Ted Dog wrote:
That was a old Unix joke, with a hidden dirty message. Embarassed


Missed the dirty joke, shucks, English not being my mother tongue... Wink

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
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Sun 25 Jan 2015, 05:20    Post subject:  

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
[url]:http://www.greenwoodsoftware.com/less[/url]. 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:
  <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:
</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:
  <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:
</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:
cd /root/Choices/ROX-Filer
rox -p=$PWD/PuppyPin


or restart from the initial black console with
Code:
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
xerrs_log-0.1.pet
Description 
pet

 Download 
Filename  xerrs_log-0.1.pet 
Filesize  40.51 KB 
Downloaded  195 Time(s) 

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Tue 27 Jan 2015, 15:44    Post subject:  

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
xerrs_log-entry-in-aemenu.jpg
 Description   Please forgive my French! ;)
 Filesize   34.24 KB
 Viewed   145 Time(s)

xerrs_log-entry-in-aemenu.jpg


_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 14544
Location: Gatineau (Qc), Canada

PostPosted: Thu 05 Feb 2015, 17:51    Post subject:  

Hello.

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

its "cousin" (so to speak) here:
http://murga-linux.com/puppy/viewtopic.php?p=826384&sort=lastpost#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 Wink, or from the Xorg people not
understanding utf-8 properly Wink, 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!) Smile

musher0

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1148s ][ Queries: 13 (0.0208s) ][ GZIP on ]