Can anyone suggest a Unix command or c-shell algorithm to simulate to behavior of "wall" command minus the "all users"? What I'm trying to do is to send a notice to just one particular user but i dont want other remotely-logged-on users to receive the message (on the pseudo-terminals). I cannot use the "write" command for three reasons:
I (sender) will not be typing the message from standard input (instead, i will be using a file
input)
I (sender) is not logged in to the same host as the receiver (but the exact hostname of the receiver is determined)
I want the message to appear on all terminals of the intended receiver.
Can anyone suggest a Unix command or c-shell algorithm to simulate to behavior of "wall" command minus the "all users"? What I'm trying to do is to send a notice to just one particular user but i dont want other remotely-logged-on users to receive the message (on the pseudo-terminals). I cannot use the "write" command for three reasons:
I (sender) will not be typing the message from standard input (instead, i will be using a file
input)
I (sender) is not logged in to the same host as the receiver (but the receiver's host is known)
I want the message to appear on all terminals of the intended receiver.
my lord this is ugly - but i am sleepy, so take it or leave it ;).
there is probably a better solution, however given what comes standard on a unix system (talk, write and wall) - writing a script around 'write' would work... something like the following:
#!/bin/ksh
user=$1 # 1st arg, recipient
file=$2 # 2nd arg, file containing message
if [[ ! -n "${user}" ]]; then
echo "you did not enter a user, aborting"
exit 0
fi
# if no file, enter one line to send
#
if [[ ! -f "${file}" ]]; then
echo "enter a one line message to send to ${user}"
read line
if [[ -n "${line}" ]]; then
echo "${line}" > $0.$$
file=$0.$$
else
echo "you did not enter any text, aborting"
exit 0
fi
fi
# write the file to all sessions of the user
#
for u in $(who | grep "^${user} " | awk '{print $1":"$2}'); do
a=$(echo "${u}" | cut -d: -f1,1)
b=$(echo "${u}" | cut -d: -f2,2)
cat ${file} |write $a $b
done
# remove temp file if exists
#
if [ -f $0.$$ ]; then
rm $0.$$
fi
I already have the script for determining the specific user (in a specific host) and the file, so I just have to find a way to send.
# write the file to all sessions of the user
#
for u in $(who | grep "^${user} " | awk '{print $1":"$2}'); do
a=$(echo "${u}" | cut -d: -f1,1)
b=$(echo "${u}" | cut -d: -f2,2)
cat ${file} |write $a $b
done
# remove temp file if exists
#
if [ -f $0.$$ ]; then
rm $0.$$
fi
This is very helpful. Will translate this to cshell and play around with it.
Question. The for-loop uses "who" and "write"... it means sender should be remotely logged in to the same host of the receiver ? What part determines the host to which to send the message?