Shell cron script/utility to make screenshots and periodically emailing

HI, FreeBSD Gurus !

Please suggest me tool/sys utility/script that :
- constantly running in a background under root privilege;
- saving local-attached terminal (monitor on server's VGA output, no any GUI used) screenshot to destination folder;
- periodically (hourly or daily, or certain day of week, or certain week of month) emailing with pre-defined message text (including server name, IP, time/date stamp, general info about hardware and installed software, general info about resources used (CPU load, MEM pressure, disk usage and I/O rates on the moment if email creating)) and the last of the screenshots attached;

Thank You a lot about all DETAILED suggestions.
Have a nice day!

P.S.
I well know about the MGMT/monitoring platforms like Prometheus, etc. exist, but I need/asking exactly shell script that doing that I asking for.

UPDATE (little bit explain from other angle of view)
As You may see by screenshots below in this thread, the are:
- rack server for hi-loading, w/ or w/o attached locally 17" monitor;
- after booting complete, the btop/bpytop automatically started on ttyv0 for server current state visual control by local tech stuff;

Also, there would be (and this is what I exactly asking for) some sh/zsh shell script to 24/7 periodically making screenshots (I think that would be "get dump of ttyv0 output, format it to bitmap and save as a .jpg/.png file) of btop/bpytop output (ASCII colors control, TUI interface), place this .jpg/.png to certain directory, and sending by schedule mail with this .jpg/.png attached and saving to remote cloud like Amazon S3/private collocation server/VPS).

Tech stuff using this "set of btop/bpytop states" as one of source of collected data for QC/QA (together with Prometheus, Grafana....).
 
Last edited:
By screenshot do you mean graphic/bitmap so there’s a GUI being used?

I have a cron job that appends the output from top to a file every minute - do you mean something like that?

So email the output of some command line tools OR a GUI screenshot?

Or both of those or something else entirely?
 
By screenshot do you mean graphic/bitmap so there’s a GUI being used?
Thank You for asking!
No any GUI used (and no in roadmap for future :) This is just rack server).
(Sorry, I forgot this note in initial message. Fixed)
I have a cron job that appends the output from top to a file every minute - do you mean something like that?
No, I mean .jpg/.png 16-color image file that contain screenshot, automatically named like

[host_name]_on_[date mm/dd/yyyy]-at-[time HH_MM_SS]_scrnshot[.ext jpg/png]

Example:
prod-web-srv.local_on_3_2_2023_at_12_15_00_scrnshot.jpg
So email the output of some command line tools OR a GUI screenshot?
Email could contain:
1. General info about server (output of certain built-in FreeBSD utils, env, pkg info, etc... Like this https://bash.cyberciti.biz/monitoring/freebsd-linux-system-information/ and this https://www.cyberciti.biz/tips/freebsd-display-information-about-the-system.html and this https://bash.cyberciti.biz/monitoring/getsysinfo.bash.html );
2. Attached .jpg/.png
 
Why a bitmap though? It would have to be potentially huge?

Lets say you have a script that runs every minute with top output, vmstat, iostat, pkg info etc so there’s hundreds of lines of text output.

You don’t want that as text in an email? It’s got to be converted to a JPG - it would have to be quite “tall” in height to fit all the information.

So you want:

1) run script to get information in textual form
2) convert text to JPG
3) email JPG
 
Don't know those tools, they don't seem to have a man page either. But top(1) can simply be redirected to output to a file. I expect those tools to be able to do the same.
 
Why a bitmap though? It would have to be potentially huge?
16 colors 1024x768 pix - is really small

Lets say you have a script that runs every minute with top output, vmstat, iostat, pkg info etc so there’s hundreds of lines of text output.
Screenshots + cron job makes not so frequently, please see initial post: hourly, daily (certain time), weekly (certain day and time), monthly (certain day and time).

screenshot.conf
- paths
scrshots: /usr/local/etc/system-snapshot;
outputs: /usr/local/etc/system-snapshot; # if not defined - scrnshots and output .txt in same dir

- synchronize
synchro: no; # only screenshots making and put in destination dir

- daily
time: 12:15 EET

- weekly # ignored if daily section exist
day: Friday;
time: 2:00 PM EST; # if not present, make at 6:00 PM

- monthly # ignored if daily or monthly section
day: 17;
time: 4:30 PM EET; # if not present, make at 6:00 PM


You don’t want that as text in an email? It’s got to be converted to a JPG - it would have to be quite “tall” in height to fit all the information.

So you want:

1) run script to get information in textual form
2) convert text to JPG
3) email JPG
Sorry, txt output (like result of echo >>) - separate job and separate txt file, and screenshot (what I am exactly asking here) - separate file.
 
Last edited:
Don't know those tools, they don't seem to have a man page either. But top(1) can simply be redirected to output to a file. I expect those tools to be able to do the same.
Bpytop/btop just stay on screen 24/7, like top. I need something in background to "snap" an on-screen output (terminal mode, no GUI) to .jpg or .png and place it in certain dir.

Pls Google btop/bputop - great on-screen monitoring tool. I thought - the best in own class. ;)
 
Last edited:
If you want screenshot, the package ImageMagick has a utility called "import" which will capture a window or the entire screen.
import -window root blah.png

captures the whole screen to the file blah.png would be trivial enough to have shell script to periodically capture.
 
tmux capturep -p -e -S 0 -E 24|aha -b -l >file.html nearly works
aha is port/package
1677595419359.png
 
Looks like btop is more of a TUI than a GUI.
Installing from freshports and testing it on Your own machine - is a fraction of time :) Enjoy to have personal experience;)

Of course, TUI


But sadly doesn’t seem to have a run-for-x-seconds-and-then-dump option.
I asking developer for this ability last 2-3 years, but because hi live in China, he has different view on world and all updates is SOOO long.
Anyway, respect to him,- app are free, well designed and
VERY stable.


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

I read this man thank You!
UPDATE
No, I not need TrueScript, I need screenshot!

Or something like Tcl expect?
Please explain what You mean?
 
Looks nice, but I already have everything I need in my Zabbix.
Not comparable things: simply onscreen monitoring app VS powerful (but too old an bulky, Prometheus + Grafana doing this work much better and have fantastic integrations level) system for monitoring appliances.
 
Probably easiest to go through tmux for capturing curses programs' output.
tmux capturep -p -e -S 0 -E 24|aha -b -l >file.html nearly works
aha is port/package
View attachment 15710
Is tha way TMUX + AHA better than IMAGE MAGIC ?
If you want screenshot, the package ImageMagick has a utility called "import" which will capture a window or the entire screen.
import -window root blah.png

captures the whole screen to the file blah.png would be trivial enough to have shell script to periodically capture.

And what is downside of each of them?

Please note, that machine are a RACK SERVER with/without physically local attached monitor to built in VGA/XGA DB9 output.
 
aha just parses ascii(utf8) + terminal control codes / you don't need X (imagemagick seems to do for import -window
it seems that aha's output is not perfect put it probably can be fixed by using some switches or a pipe filter
also aha outputs html not images (the above is rendered in chrome/mac)
 
I have no opinion on either option, I'm just used to using ImageMagick on my *nix systems since it's a dependency of WindowMaker (my preferred GUI environment). Syntax is easy to remember, "just works".
 
aha just parses ascii(utf8) + terminal control codes / you don't need X (imagemagick seems to do for import -window
Thanks for explaining. Of course, I definitely not wont X on this hi-loading node server.

it seems that aha's output is not perfect put it probably can be fixed by using some switches or a pipe filter
What is this "pipe filter"? (Sorry I am a little nub in this)

also aha outputs html not images (the above is rendered in chrome/mac)
Hm... Strange behavior;)
 
Back
Top