<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hello everybody,</p>
<p>my scenario: in my company 6 colleagues are working in the same
office building as I am and 2 are only working from their home
office. We are all using the same server placed "out of sight" in
an other building and are connected via x2go (TCE in the office)
to the server.</p>
<p>The server (running UBUNTU 14.04) is protected against power loss
by an ups that is monitored via usb and NUT on the server. The
problem is to send messages regarding critical conditions (e.g.
power loss) to all - via x2go - connected users. This is necessary
because the NUT NOTIFYCMD script starts a controlled shutdown
sequence (putting several running virtual machines to safestate
a.s.o. and finally shutting down the server) after 3 minutes
running on battery. <br>
</p>
<p>These messages are send by nut via wall automatically but this is
not the way as none of the users has open a terminal - all are
working under their LXDE/OpenBox GUI.</p>
<p>I asked the internet but only found one hint - and I have to say
thanks to <span class="post-author vcard"><span class="fn"
itemprop="author" itemscope="itemscope"
itemtype="http://schema.org/Person">
<a data-gapiattached="true" data-onload="true"
data-gapiscan="true" class="g-profile"
href="https://www.blogger.com/profile/05259914906217943114"
rel="author" title="author profile">
<span itemprop="name">Timotheus Pokorra</span></a> who gave
me the direction with his post:
<a class="moz-txt-link-freetext" href="http://tpokorra.blogspot.de/2013/07/notify-all-users-logged-in-over-x2go-on.html">http://tpokorra.blogspot.de/2013/07/notify-all-users-logged-in-over-x2go-on.html</a>
<br>
</span></span></p>
<p><span class="post-author vcard"><span class="fn"
itemprop="author" itemscope="itemscope"
itemtype="http://schema.org/Person">I tested this and it did
not work - so I designed the following solution:</span></span></p>
<p><span class="post-author vcard"><span class="fn"
itemprop="author" itemscope="itemscope"
itemtype="http://schema.org/Person">(this will be a /THE part
of the notifycmd script from nut)<br>
</span></span></p>
<p><span class="post-author vcard"><span class="fn"
itemprop="author" itemscope="itemscope"
itemtype="http://schema.org/Person">#!/bin/bash<br>
#<br>
# NUT NOTIFYCMD script<br>
<br>
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin<br>
<br>
# ...<br>
#if [ "$NOTIFYTYPE" = "ONBATT" ]<br>
#then</span></span></p>
<p><span class="post-author vcard"><span class="fn"
itemprop="author" itemscope="itemscope"
itemtype="http://schema.org/Person"> # compose message for
wall<br>
message="$(date "+%d.%m.%Y - %H:%M:%S ")$(cat
/usr/local/bin/eam01.txt)"<br>
echo $message | wall<br>
<br>
# send message to admin by e-mail<br>
echo 'EAM - '$HOSTNAME' - '$(date)' Benutzer: '$USER 'USV
meldet STROMAUSFALL / ONBATT !' | mail -s 'EAM from'$HOSTNAME
<a class="moz-txt-link-abbreviated" href="mailto:admin@xxxxx.xx">admin@xxxxx.xx</a><br>
<br>
# get infos for x2go-user-information<br>
benutzer=`ps xaf | grep x2goagent | grep -v grep | awk '
{ print ( $(NF-2) ) }' FS='-'` # get the user names<br>
screens=`ps xaf | grep x2goagent | grep -v grep | awk '
{ print ( $(NF-1) ) }' FS='-'` # get the user displays<br>
USERCOUNT="$(echo $benutzer | wc -w)"
# number
of users / loops<br>
<br>
# start loop / action for every logged in x2go-user<br>
START=1<br>
i=$START<br>
while [[ $i -le $USERCOUNT ]]<br>
do<br>
user=`echo $benutzer | awk -v a=$i '{print $a}'`
# transfer contents (word 1,2,3...) of $benutzer
to $user<br>
display=":"`echo $screens | awk -v a=$i '{print
$a}'`".0" # compose $display (word 1,2,3... from
$screens)) ":" & number from $screens & ".0"<br>
<br>
# send message to each x2go-user<br>
sudo -u $user -S -H sh -c "zenity --text-info --html
--display=$display --filename=/usr/local/bin/eam01.txt"
</usr/local/bin/pw.txt &<br>
<br>
((i = i + 1))<br>
done<br>
</span></span></p>
<p><span class="post-author vcard"><span class="fn"
itemprop="author" itemscope="itemscope"
itemtype="http://schema.org/Person">## Loop with one second
interval to allow SIGTERM reception.<br>
#let "n = 180"<br>
#while [ $n -ne 0 ]<br>
#do<br>
# sleep 1<br>
# let "n--"<br>
#done<br>
#echo $0: commencing shutdown | wall<br>
# upsmon -c fsd<br>
#fi<br>
</span></span></p>
I know that regarding the safety questions it is not ok to read a
sudo password from a file ... we must not discuss this - but I would
be glad for any better idea - btw I know the possibilities of
changes in the sudoers file but don't want this at the moment. <br>
<br>
As messages I use text files because this gives me the possibility
(with zenity) to use html and the users finally see this popup:<br>
<br>
<img src="cid:part2.29F3C11C.3857975E@ecfsolutions.de" alt=""><br>
<br>
If someone is interested please feel free to use and test it. I
would be very much interested if someone has a better / simple
solution or would be thankful for every hint regarding the
improvement of the code.<br>
<br>
For the time being I tested this not within the notifycmd script - I
tested the interesting parts in a separate script (simulating the
notifycmd / notifytype condition) within a test environment. My
life-system-test has to wait until the weekend... <br>
<br>
Best regards<br>
Christian<br>
<br>
</body>
</html>