Shell cron script/utility to make screenshots and periodically emailing

this will create a pdf out of aha's output |reads html from stdin, writes pdf to stdout
requires tcl, tdom, pdf4tcl but the get the latest version from sourceforge, port is buggy

Code:
package require tdom
#lappend auto_path /extra/fs/d/tcl86/Tcl-amd64/lib
package require pdf4tcl
proc mm2p { x } {
 return [expr {$x / 25.4 * 72}]
 }
encoding system utf-8
set FONT_SIZE 18
pdf4tcl::new mypdf  -margin 0 -paper A3  -landscape 1
pdf4tcl::loadBaseTrueTypeFont Baseunifont unifont-15.0.01.ttf
pdf4tcl::createFont Baseunifont TestFont utf-8
mypdf setFont $FONT_SIZE TestFont
mypdf setFillColor 0 0 0
mypdf rectangle 0 0 [mm2p 420] [mm2p 297] -filled 1
set fh [mypdf getFontMetric height]
set fw [mypdf getCharWidth T]
set html [read stdin]
set doc [dom parse -keepEmpties -html $html ]
set rootnode [$doc documentElement]
set x0 [mm2p 5]
set y0 [mm2p 5]
set x $x0
set y $y0
set ppnodes [$rootnode selectNodes "//span/text()"]
foreach node $ppnodes {
 set pnode [$node parent]
 set bold_hack 0
 if { [$pnode hasAttribute style ] } {
  set stl [$pnode getAttribute style]
  set lsl [split $stl ";"]
  foreach s $lsl {
   if { $s == "" } { continue }
   set ss [split $s ":"]
   if { [llength $ss] == 2 } {
    switch [lindex $ss 0 ] {
     color {
      lappend gugu [list setFillColor [lindex $ss 1]]
      }
     background-color {
      lappend gugu [list setBgColor [lindex $ss 1]]
      }
     font-weight {
      if { [lindex $ss 1] == "bold" } {
       set bold_hack 1
       }
      }
     }
    }
   }

  }
 set text [$node nodeValue]
 set ltext [split $text "\n"]
 set had_nl 0
 set zz [string length $text]
 for { set i 0 } { $i < $zz } { incr i } {
  set shit [string range $text $i $i]
  if { ![info exists A($shit) ]} {
    set A($shit) 1
    lappend Z [scan $shit %c]
   }
  }
 foreach str $ltext {
  if { $had_nl } {
   set x $x0
   set y [expr {$y + $fh }]
 # puts ""
   }
   lappend gugu [list $str $x $y]
   if { $bold_hack } {
    lappend gugu [list $str [expr $x+0.3] [expr $y+0.3]]
    }
  set x [expr {$x +[string length $str] * $fw }]
#  puts -nonewline $str
  set had_nl 1
  }
 }
#puts $Z
pdf4tcl::createFontSpecEnc Baseunifont CombinedFont $Z
mypdf setFont $FONT_SIZE CombinedFont
foreach cmd $gugu {
 set n [llength $cmd ]
 if { $n == 3 } {
  mypdf text [lindex $cmd 0] -x [lindex $cmd 1] -y [lindex $cmd 2]
  } else {
  mypdf [lindex $cmd 0] [lindex $cmd 1]
   }
 }
mypdf write
mypdf destroy
Thank You !
But screenshot still needed ;)

Bpytop/btop just stay on screen 24/7, like top. I need something in background to "snap" an on-screen output (TUI, no GUI) to .jpg or .png and place it in certain dir.
 
Looks like btop is more of a TUI than a GUI.

But sadly doesn’t seem to have a run-for-x-seconds-and-then-dump option.

Would script do anything useful? i.e. run btop under script. Probably not but maybe …


Probably, this is not solution: from man page
The script utility works best with commands that do not manipulate the screen.

But btop/bpytop exactly doing that - constantly flashing view on screen.
 
Let’s bring You attention to next from app description:

#####################

Linux, Mac Os X and FreeBSD​

For correct display, a terminal with support for:

  • 24-bit truecolor (See list of terminals with truecolor support)
  • 256-color terminals are supported through 24-bit to 256-color conversion when setting "truecolor" to False in the options or with "-lc/--low-color" argument.
  • Wide characters (Are sometimes problematic in web-based terminals)
Also needs a UTF8 locale and a font that covers:

  • Unicode Block “Braille Patterns” U+2800 - U+28FF
  • Unicode Block “Geometric Shapes” U+25A0 - U+25FF
  • Unicode Block "Box Drawing" and "Block Elements" U+2500 - U+259F

Notice (Text rendering issues)​

If you are having problems with the characters in the graphs not looking like they do in the screenshots, it's likely a problem with your systems configured fallback font not having support for braille characters.

See Terminess Powerline for an example of a font that includes the braille symbols.

See comments by @sgleizes link and @XenHat linkin issue #100 for possible solutions.

If text are misaligned and you are using Konsole or Yakuake, turning off "Bi-Directional text rendering" is a possible fix.

Characters clipping in to each other or text/border misalignments is not bugs caused by bpytop, but most likely a fontconfig or terminal problem where the braille characters making up the graphs aren't rendered correctly. Look to the creators of the terminal emulator you use to fix these issues if the previous mentioned fixes don't work for you.
 
Googling on this FreeBSD forum, I find old thread (https://forums.freebsd.org/threads/how-does-one-make-console-screenshots.37456/) where another two options graphics/scr2png is just one, and graphics/xv .

Your opinion on that?


P.S.
I try to using scr2png as described in BSD manual but receive "illegal option --p" after trying
vidcontrol -p < /dev/ttyv0 > shot.png
-p and -P option are for sc not vt (see man vidcontrol). As is said in https://forums.freebsd.org/threads/get-screenshot-image-of-vt.53704/#post-301995 , with vt, it is not possible.
 
Code:
[titus@hp430 ~]$ grep -i cpu /var/run/dmesg.boot |head -1
CPU: Intel(R) Celeron(R) N4000 CPU @ 1.10GHz (1094.40-MHz K8-class CPU)
[titus@hp430 ~]$ time tmux capturep -p -e -S 0 -E 80 | aha -b -l |sed -e 's/<pre>/<pre style="font-family:unifont">/g' |tclsh8.6 z.tcl |convert - -trim out.png

real    0m2.390s
user    0m2.254s
sys    0m0.172s
used terminess font from github link above
1677714388113.png
 
Thank You for suggestion, but as I say before ANY extra loading on the server are strongly unwanted...
May be some other solution ?

No.

You already said you want pixmaps no matter what, so you get some load. The XPra solution is as lightweight as some other machinery you could use. If you want lower load than that, then keep it in text.
 
Could you have a separate monitoring machine with a GUI installed?

ssh from there into the server machine(s) and run the btop etc. programs.

Use the graphical tools on this monitoring machine to take the snapshots and email them.

Then it doesn’t matter about the extra load or tools you use - they’re all on the client/monitoring machine.

What I don’t know if is there are any issues running the TUI tools over ssh.
 
Could you have a separate monitoring machine with a GUI installed?
Of course.

ssh from there into the server machine(s) and run the btop etc. programs.

Use the graphical tools on this monitoring machine to take the snapshots and email them.

Then it doesn’t matter about the extra load or tools you use - they’re all on the client/monitoring machine.
We already using monitoring toolset like Prometheus, LibreNMS, Splunk, Network Weathermap, ...

The script I asking here is for one small goal. No more, no less. :)
What I don’t know if is there are any issues running the TUI tools over ssh.
Depend on app: as I wrote before, no any issues with bpytop over SSH/VPN.

Just as off-topic:

BTW, some time ago I spend around a two days to testing may be all of "on screen system monitoring tools with TUI" for FreeBSD, so, trust me,- bpytop ARE THE BEST. The next step - only serious systems like Prometheus, LibreNMS.
Sorry Nagios and Zabbix just outdated in modern world. Another 5-7 years and may be only small part of Zabbix installations would be still exist.
 
Code:
[titus@hp430 ~]$ grep -i cpu /var/run/dmesg.boot |head -1
CPU: Intel(R) Celeron(R) N4000 CPU @ 1.10GHz (1094.40-MHz K8-class CPU)
[titus@hp430 ~]$ time tmux capturep -p -e -S 0 -E 80 | aha -b -l |sed -e 's/<pre>/<pre style="font-family:unifont">/g' |tclsh8.6 z.tcl |convert - -trim out.png

real    0m2.390s
user    0m2.254s
sys    0m0.172s
used terminess font from github link above
View attachment 15726
Amazing work!
Thank You so much!
You make my day a little bit shining!

Running to try out in my server...;)
 
Hm... Already added to my favorites on GitHub ;)
May be from the times when I try to solving problem with switching to highest res on one of servers MGA 200a for bpytop...

tty does not matter just use the monitoring software from tmux
Ok, thank You for explanation.
 
pkg install tcl86 tdom pdf4tcl Imagemagick7-nox11
if pdf is good enough you don't need ImageMagick
pdf4tcl 0.8 from ports/packages is buggy but you can replace its files with the latest version (sourceforge)
pdf4tcl is platform independent (just a tcl script)
 
Back
Top