向其他用户发送消息

Ric*_*ida 70 command-line networking terminal messaging

是否有任何命令可以通过 Linux shell 向同一网络上的其他人发送消息?我正在使用write user然后编写消息本身。但是有任何命令没有显示我的用户名或者我试图给他们发消息

我正在使用的命令将向我尝试联系的用户显示这一点(代码取自网络):

Message from root@dev.example.com on pts/1 at 17:11 ...
Run Code Online (Sandbox Code Playgroud)

slm*_*slm 103

我知道这样做的唯一直接方法是使用wall命令。这可用于通过-n开关省略发送者的标识。

例子

$ sudo wall -n hi

Remote broadcast message (Fri Nov  8 13:49:18 2013):

hi
Run Code Online (Sandbox Code Playgroud)

使用回声

这种替代方法更像是一种 hack,因为它不是通过显式工具完成的,但是您可以将文本回显到用户的终端,假设您知道他们在哪个终端上。

例子

$ 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
Run Code Online (Sandbox Code Playgroud)

假设您知道用户saml实际上在其中一个伪终端上,您可以像这样直接将文本回显到该设备。从终端pts/1

$ sudo echo "Let's go have lunch... ok?" > /dev/pts/4
$ 
Run Code Online (Sandbox Code Playgroud)

结果pts/4

$ man rsync
$ Let's go have lunch... ok?
Run Code Online (Sandbox Code Playgroud)

  • @Exsound - 正确。没有办法通过我见过的任何其他方法在没有您的身份证明的情况下发送消息。 (2认同)

小智 10

您可以使用此功能:)。
将该代码复制到具有名称的文件中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
Run Code Online (Sandbox Code Playgroud)

如何使用:
转到终端并输入:

chmod +x SendMessage.sh
./SendMessage.sh
Run Code Online (Sandbox Code Playgroud)

你可以发送消息。