73

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 ...
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Ricardo Almeida
  • 855
  • 1
  • 8
  • 6

2 Answers2

106

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?
slm
  • 363,520
  • 117
  • 767
  • 871
  • But 'wall' sends the message to all users logged in right? – Ricardo Almeida Nov 08 '13 at 18:51
  • 2
    @Exsound - correct. There isn't a way to send a message without your identification through any other method I've seen. – slm Nov 08 '13 at 18:52
  • 1
    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. – Michael Suelmann Nov 08 '13 at 18:57
  • 1
    @Exsound - you can also echo directly to the terminal, see update. – slm Nov 08 '13 at 18:59
  • @Exsound - you're welcome, thanks for the Q. – slm Nov 08 '13 at 19:06
  • @slm I feel so empowered now that I can send covert messages to users – Alexej Magura Oct 25 '16 at 16:56
  • 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` – Martin Konecny Aug 01 '17 at 16:29
10

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.

taliezin
  • 9,085
  • 1
  • 34
  • 38
Hajime Beddai
  • 119
  • 1
  • 2