[X2Go-User] Send message to all x2go-users logged in

ECF Solutions ecf at ecfsolutions.de
Wed Jul 27 18:27:33 CEST 2016


Hello everybody,

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.

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.

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.

I asked the internet but only found one hint - and I have to say thanks 
to Timotheus Pokorra 
<https://www.blogger.com/profile/05259914906217943114> who gave me the 
direction with his post: 
http://tpokorra.blogspot.de/2013/07/notify-all-users-logged-in-over-x2go-on.html 


I tested this and it did not work - so I designed the following solution:

(this will be a /THE part of the notifycmd script from nut)

#!/bin/bash
#
# NUT NOTIFYCMD script

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin

# ...
#if [ "$NOTIFYTYPE" = "ONBATT" ]
#then

    # compose message for wall
     message="$(date "+%d.%m.%Y - %H:%M:%S ")$(cat 
/usr/local/bin/eam01.txt)"
     echo $message | wall

    # send message to admin by e-mail
    echo 'EAM - '$HOSTNAME' - '$(date)' Benutzer: '$USER 'USV meldet 
STROMAUSFALL / ONBATT !' | mail -s 'EAM from'$HOSTNAME admin at xxxxx.xx

    # get infos for x2go-user-information
       benutzer=`ps xaf | grep x2goagent | grep -v grep | awk ' { print 
( $(NF-2) ) }' FS='-'`     # get the user names
       screens=`ps xaf | grep x2goagent | grep -v grep | awk ' { print ( 
$(NF-1) ) }' FS='-'`       # get the user displays
       USERCOUNT="$(echo $benutzer | wc -w)"                           
                            # number of users / loops

    # start loop / action for every logged in x2go-user
     START=1
     i=$START
     while [[ $i -le $USERCOUNT ]]
     do
       user=`echo  $benutzer | awk -v a=$i '{print $a}'`             # 
transfer contents (word 1,2,3...) of $benutzer to $user
       display=":"`echo  $screens | awk -v a=$i '{print $a}'`".0"        
# compose $display (word 1,2,3... from $screens)) ":" & number from 
$screens & ".0"

    # send message to each x2go-user
       sudo -u $user -S -H sh -c "zenity --text-info --html 
--display=$display --filename=/usr/local/bin/eam01.txt" 
</usr/local/bin/pw.txt &

           ((i = i + 1))
     done

## Loop with one second interval to allow SIGTERM reception.
#let "n = 180"
#while [ $n -ne 0 ]
#do
#         sleep 1
#         let "n--"
#done
#echo $0: commencing shutdown | wall
#        upsmon -c fsd
#fi

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.

As messages I use text files because this gives me the possibility (with 
zenity) to use html and the users finally see this popup:



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.

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...

Best regards
Christian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x2go.org/pipermail/x2go-user/attachments/20160727/389375e1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 31827 bytes
Desc: not available
URL: <http://lists.x2go.org/pipermail/x2go-user/attachments/20160727/389375e1/attachment-0001.png>


More information about the x2go-user mailing list