User listing.




Sometimes you may want to know who has access to a system and even some of the applications that might be installed.  All you have to do is to get a user listing.

lsuser.sh
[code]
 #=================================
# lsuser - list users
#=================================
# Assignments
# --------------------------------
datafile="/etc/passwd"
# end assignments

#=================================

# Data input
#---------------------------------
while read line
do echo $line | cut -d: -f1
done < $datafile
[/code]

$ chmod +x lsuser.sh

$ ./lsuser.sh

root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
...
...

Note if the batch file is is a user accessible area on another server you can

$ ssh oeorgan1 "lsuser.sh"

Now the write command

$ write eddie
test
<ctrl-d>



Message from eddie@oedt01 on pts/1 at 14:19 ...
test
EOF

write sends a message to another user.
Syntax

write user [tty]

Description

The write utility allows you to communicate with other users, by copying lines from your terminal to theirs.

When you run the write command, the user you are writing to gets a message of the format:

Message from yourname@yourhost on yourtty at hh:mm ...

Any further lines you enter will be copied to the specified user's terminal. If the other user wants to reply, they must run write as well.

When you are done, type an end-of-file or interrupt character. The other user will see the message ‘EOF’ indicating that the conversation is over.

You can prevent people (other than the super-user) from writing to you with the mesg command.

If the user you want to write to is logged in on more than one terminal, you can specify which terminal to write to by specifying the terminal name as the second operand to the write command. Alternatively, you can let write select one of the terminals; it will pick the one with the shortest idle time. This is so that if the user is logged in at work and also dialed up from home, the message will go to the right place.

The traditional protocol for writing to someone is that the string ‘-o’, either at the end of a line or on a line by itself, means that it is the other person's turn to talk. The string ‘oo’ means that the person believes the conversation to be over.
Options
user     The user to write to.
tty     The specific terminal to write to, if the user is logged in to more than one session.
Examples

write hope

Write a message to the user hope. After entering this command, you will be placed on a blank line, where everything you type will be sent to the other user (line by line). Typing the interrupt character (CTRL-C, by default) will return you to the command prompt, and end the write session.

write hope tty7

Write a message to the user hope on terminal tty7.

You can even send messages with sendmessage.sh

sendmessage.sh
[code]

#!/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
[/code]

$ chmod +x sendmessage.sh

$./sendmessage.sh

You can use the mesg command to control non-root messages to you

The mesg command allows you control write access to your terminal by other users.
Syntax

mesg [n|y]

Description

The write command allows other users to send a message to your terminal session; the mesg command is used to toggle these messages on or off.
Options
n     Prevents the display of terminal messages from other users. This is like using a "do not disturb" sign.
y     Allows messages to be displayed on your screen.

If no option is given, mesg displays the current access state of your terminal.
Examples

mesg y

Allow other users to send you messages.

mesg n

Disallow other users from being able to send you messages.

mesg

Display the current write status of your terminal.

Let's not forget talk

Chat with other logged-in users.
Syntax

talk person [ttyname]

Description

Talk is a visual communication program which copies lines from your terminal to that of another user, much like an instant messenger service. When first called, talk contacts the talk daemon on the other user's machine, which sends the message below.

Message from TalkDaemon@his_machine...
talk: connection requested by your_name@your_machine.
talk: respond with: talk your_name@your_machine

to that user. At this point, he then replies by typing

talk your_name@your_machine

It doesn't matter from which machine the recipient replies, as long as his login name is the same. Once communication is established, the two parties may type simultaneously; their output will appear in separate windows. Typing control-L (^L) will cause the screen to be reprinted. The erase, kill line, and word erase characters (normally ^H, ^U, and ^W, respectively) will behave normally. To exit, just type the interrupt character (normally ^C); talk then moves the cursor to the bottom of the screen and restores the terminal to its previous state.

talk supports scrollback; use esc-p and esc-n to scroll your window, and ctrl-p and ctrl-n to scroll the other window.

If you do not want to receive talk requests, you may block them using the mesg command. By default, talk requests are normally not blocked. Certain commands, in particular nroff, pine, and pr, may block messages temporarily in order to preserve their own output.
Options
person     If you want to talk to someone on your own machine, then person is just the person's login name. If you want to talk to a user on another host, then person is of the form 'user@host'.
ttyname     If you want to talk to a user who is logged in more than once, the ttyname argument may be used to indicate the appropriate terminal name, where ttyname is of the form 'ttyXX' or 'pts/X'.
Examples

talk hope

Talk to user hope.

Find out who is on to send messages.

$ w
 14:43:28 up  1:46,  2 users,  load average: 0.09, 0.08, 0.08
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
eddie    pts/1    oedt01           13:35    0.00s  1.38s  0.03s w

or

$ ssh oeorgan1 "w"
 14:44:34 up  1:47,  2 users,  load average: 0.03, 0.07, 0.07
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
eddie    pts/1    oedt01           13:35    1:06   1.36s  1.36s -bash

Have fun.

Comments

Popular posts from this blog

Guiless?

Web.com and Network Solutions, the Walmart of the internet.

MSOffice vs Libreoffice