Differences

This shows you the differences between two versions of the page.

Link to this comparison view

konsoleandexpect [2015/08/19 10:08] (current)
yassine chaouche created
Line 1: Line 1:
  
 +\\
 +[[index|Home]] > [[computers|computers]] > [[linux]] > [[kde|kde]] > [[konsoleandexpect|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.
 +
 +{{http://​i.imgur.com/​sYJyZ2P.png}}
 +
 +
 +{{http://​i.imgur.com/​CpAjrCU.png}}
 +
 +
 +{{http://​i.imgur.com/​aSjkalR.png}}
 +
 +Pay attention here : the label says that one must uncheck a box in the konsole configuration in order for the geometry to work.
 +
 +{{http://​i.imgur.com/​qulmgZh.png}}
 +
 +
 +{{http://​i.imgur.com/​ZPU4eKN.png}}
 +
 +Now the result (click to enlarge) ​
 +
 +{{http://​i.imgur.com/​qOt0mfB.png?​800x500}}
 +
 +Those six konsoles were opened with the shortcut "​Ctrl-Meta-m"​. This is bound to launch this bash script ​
 +
 +<​code>​
 +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 ~ $ 
 +</​code>​
 +
 +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
 +
 +{{http://​i.imgur.com/​dOmdbOD.png}}
 +{{http://​i.imgur.com/​9NtCcBi.png}}
 +{{http://​i.imgur.com/​I1z4BVj.png}}
 +
 +
 +=== Bonus ===
 +
 +One of my expect scripts you can build upon :
 +
 +<​code>​
 +#​!/​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
 +</​code>​
 +
 +I myself have built upon the work of [[https://​twitter.com/​JournalDev | Pankaj Kumar]] over at [[ http://​www.journaldev.com/​1405/​expect-script-example-for-ssh-and-su-login-and-running-commands | 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 : [[http://​twitter.com/​ychaouche|@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)