Home > computers > linux > kde > konsoleandexpect | About

How to monitor 6 different logs on a distant machine with a single key combination and no password typing ?

Since we need many consoles, we need to fix their sizes so that they can fit in a single screen

How to open konsole with a specific size ?

We are going to make a new profile, monitor, that will hold the geometry we want.

Pay attention here : the label says that one must uncheck a box in the konsole configuration in order for the geometry to work.

Now the result (click to enlarge)

Those six konsoles were opened with the shortcut "Ctrl-Meta-m". This is bound to launch this bash script

ychaouche@ychaouche-PC ~ $ cat SCRIPTS/messagerie.monitor
konsole --profile monitor -e /home/ychaouche/SCRIPTS/messagerie.postfix.log.main.expect
konsole --profile monitor -e /home/ychaouche/SCRIPTS/messagerie.postfix.log.warn.expect
konsole --profile monitor -e /home/ychaouche/SCRIPTS/messagerie.postfix.log.main.filter.expect
konsole --profile monitor -e /home/ychaouche/SCRIPTS/messagerie.auth.log.expect
konsole --profile monitor -e /home/ychaouche/SCRIPTS/messagerie.fail2ban.log.expect
konsole --profile monitor -e /home/ychaouche/SCRIPTS/messagerie.terminal.expect

ychaouche@ychaouche-PC ~ $ 

The script has six commands, each command is launching konsole with a -e switch. The -e switch tells konsole what command to launch at startup. Each of the -e commands is a little expect script that ssh to a machine, su'es, then launches a specific command on the distant machine (as root). This is usually tail -f on a certain file, or a specific command (as is the case with /home/ychaouche/SCRIPTS/messagerie.postfix.log.main.filter.expect).

Here's how to configure this shortcut

Bonus

One of my expect scripts you can build upon :

#!/usr/bin/expect 
spawn ssh serveur@10.10.10.19 -p 22022
expect "assword" {send "thepassword\r"} # this catches password as well as Password
expect -ex "$" {send "su\r"}
expect "Password:" {send "theotherpassword\r"}
expect "#" {send "tail -f /var/log/auth.log\r"}
interact

I myself have built upon the work of Pankaj Kumar over at journaldev. Credit goes to him for this straightforward and hands-on example that let me write this expect script in a minimum amount of time and effort !


contact : @ychaouche yacinechaouche at yahoocom


QR Code
QR Code How to monitor 6 different logs on a distant machine with a single key combination and no password typing ? (generated for current page)