Hi,

Some may know konsole adds no /utmp entry (good) but also
currently kwrited only wastes memory (bad).  I've had to
write a little script to make use kwrited.  (If I shutdown
our server a second time without some users getting an info msg
.... oh oh).

I'm open for suggestions and better solutions ;)

Share and enjoy,
Achim

#!/bin/bash

## kdewall:     simple wall for Debian/KDE
##
##              KDE KDE users which use only konsole never see
##              wall messages (no utmp entry 'cause Debian
##              does not like libtempter and it has not HAVE_LIBUTIL)
##              (at least now kwrited does not only waste memory :)
                
prg="${0##*/}"

if [ $# -ne 1 ]; then
        echo "Usage:  $prg  msgfile" >&2
        exit 
fi

if [ -f "$1" -a -r "$1" ]; then
        msgfile="$1"
else
        echo "File not found or not readable: '$1'" >&2
        exit 
fi

msgheader="Message from '[EMAIL PROTECTED]' (`date`):"

# selection of kwrited processes:
#       o find all /bin/cat processes
#       o check if parent is kwrited
#       o write to all ptys of bin

echo "informing kwriteds ..."
ps ax -o pid,ppid,cmd | grep /bin/cat | grep -v grep |
        while read pid ppid foo; do
                #ps -o pid,ppid,cmd -p $ppid;
                #ps -o ppid,pid,tty,cmd -p $pid --no-header

                pty=/dev/"`ps -o tty -p $pid --no-header`"      
                if [ -w "$pty" ]; then
                        case "$pty" in
                           /dev/pts/[0-9]*)
                                printf "\n$msgheader\n" > "$pty"
                                cat "$msgfile"          > "$pty"
                                printf "\n--\n"                 > "$pty"

                                echo "$prg: msg send to '$pty'"
                                ;;
                           *)
                                echo "$prg: Invalid pty name: '$pty'" >&2
                                ;;
                        esac
                else
                        echo "$prg: '$pty' not writeable" >&2
                fi
        done
echo "using wall ..."
wall "$msgfile"

-- 
  To me vi is Zen.  To use vi is to practice zen. Every command is
  a koan. Profound to the user, unintelligible to the uninitiated.
  You discover truth everytime you use it.
                                      -- [EMAIL PROTECTED]


Reply via email to