On Tue, 30 Oct 2007 09:19:28 +0700
Donny Christiaan <[EMAIL PROTECTED]> wrote:

> Or you can just use "wall" from linux shell.
> 

I wish I would have known about "wall". Sorry to come a but late to the
discussion, but I have not checked on my list email in a long time.

Anyway, I had written up a script as well.  Figured it might help you
(or someone else) out.

  - can be configured to gmessage, kmessage, xmessage (and probably
    others) to display the message on the thin-clients.
  - Assumes that you do NOT want the message to display on the server
    (in my small environment, I have 4 clients and 1 server, so the 
    server is also MY desktop)
  - can send message to just one user (base on login username) or all
    users
  - sends message based on login, so it does not matter what desktop
    environment the users are using.




-- 
http://gentgeen.homelinux.org

#############################################################
 Associate yourself with men of good quality if you esteem    
 your own reputation; for 'tis better to be alone then in bad 
 company.        - George Washington, Rules of Civility
#!/bin/bash
# ======================================================================
# assign better names to the arguements provided on the command line
# ======================================================================
# $* means every arguement
# The 'shift' is needed to make sure to grab everything 
# AFTER the first arguement 
username=$1
shift
message=$*

# I like gmessage, but you can use kmessage or xmessage. Just replace 
# the next variable with the message program you want to use along with
# any arguments you want to send with it (except for the -display arguement
# that is covered in the script)
msgprg="gmessage -buttons \"GTK_STOCK_CLOSE\" -center -timeout 60 -wrap -geometry 400x200 -title \"Message from the Administrator\""

# ======================================================================
# A number of functions just too help me keep things together, and make
# trouble shooting easier.  
# ======================================================================
# Function to respond to usage errors at the command line
function usage ()
{
   echo " "   
   echo " THIS SCRIPT MUST BE RUN AS ROOT!!!"   
   echo " THIS SCRIPT MUST BE RUN AS ROOT!!!"   
   echo " THIS SCRIPT MUST BE RUN AS ROOT!!!"   
   echo " "
   echo "  usage: $0 [USERNAME] [MESSAGE]"
   echo "         where USERNAME can be 1 specific user "
   echo "         or if USERNAME=all then message goes to all users logged in"
   echo " "
   echo "         everything after USERNAME will become part of the message" 
}

# Function to make sure the user is actually logged onto the server
function user_check ()
{
   check=$(who | awk '{print $1}' | grep ^"$username" | uniq )
   if [ -f $check ]; then
       echo "     Sorry, $username is not currently logged on"
       exit
   fi
}

# Function to send message to all users
function msg_all ()
{
   users=$(who | awk '{print $1}' | sort | uniq )
   for user in $users
   do
      display=$(who | grep ^"$user" | awk '{print $2}' | grep -e ":" )
      # if the display comes back as just ":0" that means the user is logged
      # onto the server (at least on my machine)
      if [ "$display" = :0 ]; then
         display="`hostname -f`:0.0"
      fi
      #Use this line for access_control
      su 2>/dev/null 1>&2 -c "$msgprg -display $display $message" - $user &
      # Use this line if "disable_access_control=y" is in the lts.conf file
      # $msgprg -display $display $message 2>/dev/null &
   done
}

# Function to send message to one user
function msg_one ()
{
      # need to get the display just for that one user
      display=$(who | grep ^"$username" | awk '{print $2}' | grep -e ":" )
      # if the display comes back as just ":0" that means the user is logged
      # onto the server (at least on my machine)
      if [ "$display" = :0 ]; then
         display="`hostname -f`:0.0"
      fi
      su 2>/dev/null 1>&2 -c "$msgprg -display $display $message" - $username &
}
# ======================================================================
# Stuff just to check that everything is OK
# ======================================================================
# Make sure that there were at least 2 arguments proved
if [ $# -lt 2 ]; then
   usage
   exit
fi

# Make sure that the user is really logged in as root
if [ $USER != "root" ]; then 
   usage
   exit
fi 

# ======================================================================
#  Now that I have all the checking done, now it is time for the work
# ======================================================================
if [ "$username" = all ]; then
   msg_all
   exit
else
   user_check
   msg_one
   exit
fi
exit
#end script
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_____________________________________________________________________
Ltsp-discuss mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-discuss
For additional LTSP help,   try #ltsp channel on irc.freenode.net

Reply via email to