Sending messages to another user

327,359

Solution 1

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?

Solution 2

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.

Share:
327,359

Related videos on Youtube

Ricardo Almeida
Author by

Ricardo Almeida

Updated on September 18, 2022

Comments

  • Ricardo Almeida
    Ricardo Almeida over 1 year

    Is there any command to send messages through the Linux shell to other people on the same network? I'm using write user and then write the message itself. But there's any command that doesn't show my username or that I'm trying to message them

    The command I'm using will show this to the user I'm trying to contact (code taken from the web):

    Message from [email protected] on pts/1 at 17:11 ...
    
  • Ricardo Almeida
    Ricardo Almeida over 10 years
    But 'wall' sends the message to all users logged in right?
  • slm
    slm over 10 years
    @Exsound - correct. There isn't a way to send a message without your identification through any other method I've seen.
  • Michael Suelmann
    Michael Suelmann over 10 years
    On my system syslog is configured to send messages with level emerg via wall, so logger -p emerg hi works the same as the 1st method above (except syslogd is shown as sender), but doesn't need sudo.
  • slm
    slm over 10 years
    @Exsound - you can also echo directly to the terminal, see update.
  • slm
    slm over 10 years
    @Exsound - you're welcome, thanks for the Q.
  • dibs
    dibs over 8 years
    Confirmed as awesome.
  • Anwar
    Anwar almost 8 years
    Super Awesome I would say.
  • Alexej Magura
    Alexej Magura over 7 years
    @slm I feel so empowered now that I can send covert messages to users
  • Martin Konecny
    Martin Konecny almost 7 years
    You can't use sudo echo "Let's go have lunch... ok?" > /dev/pts/4. The permissions don't carry over after the right chevron character > where you actually need the permission. You need to do sudo su to completely switch to root and then run echo "Let's go have lunch... ok?" > /dev/pts/4
  • Juan
    Juan over 3 years
    I'm not sure if is since ubuntu 14 or ubuntu 16, but in ubuntu 18.04 the command who am i has changed to who