<div dir="ltr">On 17 April 2013 21:09, Morsiani, Massimo <span dir="ltr"><<a href="mailto:massimo.morsiani@gilbarco.com" target="_blank">massimo.morsiani@gilbarco.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">is there anyone that is using one script to check if root user is logged on Unix/Linux machines?<br>


Or is there anyone that is using "<a href="http://xymond_rootlogin.pl" target="_blank">xymond_rootlogin.pl</a>" and can explain me how to use it?<br>
Thanks in advance for the support.<br></blockquote><div><br></div><div style>IMHO, this script seems overkill, given what's now possible within Xymon these days.  The "who" output is already available in the client data, and could be extracted and analysed server-side with something like:</div>

<div style><br></div><div style>#!/bin/sh</div><div style>HOSTLIST=`xymongrep rootcheck`</div><div style>for HOSTNAME in $HOSTLIST; do</div><div style>  WHO=`xymon localhost 'clientlog name.of.server section=who"`<br>

</div><div style>  [ "$WHO" ] || continue # skip hosts without [who]</div><div style>  if echo "$WHO" | grep "^root" >/dev/null; then</div><div style>    MSG="status $HOSTNAME.root red root logins detected"</div>

<div style>  else<br></div><div>    MSG="status $HOSTNAME.root green no root logins detected"</div><div style>  fi</div><div style>  xymon $XYMSRV "$MSG<br></div><div style>$WHO"</div><div style>done</div>

<div style><br></div><div style>This just finds all the hosts.cfg entries with "rootcheck" present, and reports where "who" shows that root is logged in.  This would be run from tasks.cfg.</div><div style>

<br></div><div style>Another way to do this, without having to create and maintain an actual script file, is to use backticks to create a virtual log file entry in client-local.cfg, like so:</div><div style><br></div><div style>

<div>log:`exec 2>/dev/null; { grep '^$' /tmp/who.log >/dev/null && >/tmp/who.log || echo "" >>/tmp/who.log; } && who >> /tmp/who.log && echo /tmp/who.log`:10240</div>

<div><br></div><div style>This collects lines from a virtual logfile /tmp/who.log, that contains the who output.  This allows you to monitor the who logfile with analysis.cfg, like so:</div><div style><br></div><div style>

HOST=*</div><div style><div>  LOG /tmp/who.log %^root COLOR=red TEXT="Root login detected"</div><div><br></div><div style>This backticks scriptlet is a little complicated because it needs to make sure the virtual logfile size changes every time, otherwise Xymon's logfetch process might not detect any difference in the file and not report anything.</div>

<div><br></div><div style>J</div><div style><br></div></div></div></div></div></div>