Sending messages to another user
The only straightforward way I know of doing this is to use the wall
command. This can be used to omit the sender's identification, via the -n
switch.
Example
$ sudo wall -n hi
Remote broadcast message (Fri Nov 8 13:49:18 2013):
hi
using echo
This alternative method is more of a hack, since it isn't done through an explicit tool but you can echo text out to a users' terminal assuming you know which one they're on.
Example
$ w
13:54:26 up 2 days, 36 min, 4 users, load average: 4.09, 4.20, 3.73
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
saml tty1 :0 Wed13 2days 3:55m 0.04s pam: gdm-password
saml pts/0 :0.0 Wed13 24:16m 0.35s 0.35s bash
saml pts/1 :0.0 Wed20 0.00s 3.71s 0.00s w
saml pts/4 :0.0 01:20 12:33m 0.36s 0.05s man rsync
Assuming you know user saml
is in fact on one of the pseudo terminals you can echo text to that device directly like so. From terminal pts/1
:
$ sudo echo "Let's go have lunch... ok?" > /dev/pts/4
$
Result on pts/4
:
$ man rsync
$ Let's go have lunch... ok?
You can use this function :).
Copy that code into file with name SendMessage.sh
#!/bin/bash
SendMessage()
{
com=`tty`
set `who am i`
who | grep -v "$1" >filef.txt
exec < filef.txt
array=""
while read line
do
set $line
echo $1
array+=($1)
done
rm filef.txt
exec <$com
echo "====================> Select User Number <===================="
echo
select userName in ${array[@]}
do
UserNam=$userName
if [ -n $UserNam ]; then
break
fi
done
unset array #Clear the Array
echo
echo
echo "===================================> Message Body <==================================="
mesg y
read -p "put here your Message==> " messagel
echo $messagel | write $UserNam
if [ $? -eq 0 ]; then
echo "It has been sent successfully.............ok"
#return 0
else
echo "Message Failed to send ..............No!!"
echo "Maybe It is not available for you To send Message To hem "
return 1
fi
}
SendMessage
How to use:
Go to Terminal and type:
chmod +x SendMessage.sh
./SendMessage.sh
And you can send message.