write Command
Purpose
Opens a line of communication to send messages to other users on the system in real time.
Syntax
To query all messages awaiting replies from users on a host and display them with their handles, type the following:
To Reply to a Message Sent by a Utility or a Shell Script, or Redisplay the Message Associated with a Given handle, type the following:
write -hHandle, { ok | cancel | query } [ -n Host ]
To send messages to a user, optionally on another host or a particular device, type the following:
Description
The write command enables message sending over the system in real time. It provides conversation-like communication with another logged-in user. Each user alternately sends and receives short messages from the other workstation. Long messages can be sent by putting the complete message in a file and then redirecting that file as input to the write command.
For another user (as specified by the User parameter) to receive a message, that user must be logged in and must not have refused message permission. When a message is sent to a user who is not logged in, the message user not logged in appears. If the message is sent to a user who has refused message permission by setting the mesg command to no, the message write: permission denied appears.
When the write command is issued, it immediately sends the following message, along with an attention-getting sound (the ASCII BEL character) to the message recipient or target:
Message from SenderID on SenderHostname (ttynn) [Date] ...
With a successful connection, the write command sends two ASCII BEL characters to both workstations. The beep alerts the sender that the message can begin and it alerts the receiving user that a message is coming.
Sending occurs one line at a time as the Enter key is pressed. The communication link from the sender to the receiver remains open and sending continues until the Ctrl-D key sequence ends the sending link. Then an end-of-text character (<EOT>) is sent to the target workstation and the write command mode is terminated.
The receiving or target user can respond by sending a write command to the originating user. This opens a line of communication from the receiver back to the sender, enabling message responses in return. For this type of exchange, the following convention is useful: When you first write to others, wait for a response before sending any text. End a message with a signal such as o (over) to alert the other person to reply. Use oo (over and out) when the conversation is finished.
If the character ! (exclamation point) is found at the beginning of a line, the write command calls the shell to execute the rest of the line as a command.
When you write to a user who is logged in at more than one workstation or multi-using more than one process, the write command uses the first login instance found in the /etc/utmp file as the message delivery point (usually the login or console shell), and you get the message:
UserID is logged on more than one place.
You are connected to "Workstation".
Other locations are:
Workstation
When this message is received, if you wish to send the message to a location other than the initial login location, the target user can be contacted at a different location by specifying the Line of the location (tty00, for example).
Permission to write to another user is granted or denied by the individual user with the mesg command. Some commands deny message permission while they are running to prevent interference with their output. A user with root user authority can write to any workstation regardless of the workstation's message permission.
You can use the write command to converse with users on other hosts. You can identify a user on a remote host by using the -nHostName flag or the User@Host parameter. In order to write to a user on a remote host, the writesrv daemon must be running on both the current host and the remote host.
The write command is also used by the qdaemon daemon to send messages to users on other hosts and to wait for replies. There are only three valid replies:
Item | Description |
---|---|
ok | The original write exits with a status of 0. |
cancel | The original write exits with a status of 1. |
query | The message associated with the given handle is displayed. |
Parameters
Item | Description |
---|---|
User | Specifies the user ID of the person to receive the message text. |
User@Host | Specifies the user ID and remote host of the person to receive the message text. |
Line | Contacts the target user at another location (tty00, for example). |
Flags
Item | Description |
---|---|
-h Handle,Reply | Replies to a message sent by a utility or shell script using write with the reply option. The value to be used for the Handle variable is generated internally and supplied to the user in the text of the original message. The reply can be ok, cancel, or query. |
-nHost | Specifies a remote host. The Host variable may be a nickname or an internet address. |
-q | Queries all messages awaiting replies from users on a host and displays them with their handles. |
-r | Generates a message handle, places it in the message header, sends the message, and waits for a reply. This flag is used by the qdaemon daemon for operator messages and can be put in shell scripts. It is not used for interactive conversations. An exit status of 0 indicates that the reply was ok, a status of 1 indicates that the reply was cancel, and an exit status of 2 indicates that the user could not be contacted. |
- The writesrv daemon must be running on the target host in order for any of the flags to work. If you are not using either the -n flag or @Host, but using -h, -q, or -r, the writesrv daemon must be running on your host.
- If TCP/IP is not installed on
your machine but the HostName is
set, in order to converse with users on the local host using the write command
with the -h, -q, or -r flag, you must append
your host name to the end of the loopback entry in the /etc/hosts file. The original entry should
read:
The new entry should read:127.0.0.1 loopback LocalHostName
127.0.0.1 loopback LocalHostName HostName
Exit Status
This command returns the following exit values:
Item | Description |
---|---|
0 | Successful completion. |
>0 | The addressed user either is not logged on or denies permission. |
Examples
- To write a message to
a user who is logged in, enter:
Press the Enter key and type,write june
Then press the Ctrl-D key sequence to terminate the write command mode.I need to see you! Meet me in the computer room at 12:30.
If your user ID is karen and you are using workstation tty3, june's workstation displays:
Message from karen on trek tty3 Aug 17 11:55:24 ... I need to see you! Meet me in the computer room at 12:30. <EOT>
- To
hold a conversation,
enter:
Press the Enter key and type,write june
This starts the conversation. The o at the beginning of the next line means the message is over. It tells June that you are waiting for a response. Do not press Ctrl-D if you wish to continue.Meet me in the computer room at 12:30. o
Now June replies by typing:
Presses the Enter key and types,write karen
And you might respond:I'm running tests at 12:30. Can we meet at 3? o
The oo means over and out, telling June that you have nothing more to say. If June is also finished oo, then you both press Ctrl-D to end the conversation.OK--the computer room at 3. oo
- To write someone a prepared
message, enter:
This writes the contents of the message.text file to june's workstation.write june < message.text
- To
write to the person
using a certain workstation, enter:
Press the Enter key and type,write -n console
Then press the Ctrl-D key sequence.The printer in building 998 has jammed. Please send help.
This writes the message to the person logged in at the workstation /dev/console.
- To
send a message to user spuds at
host partya, enter:
Press the Enter key and type,write -n partya spuds
Then press the Ctrl-D key sequence.Your new tape has just arrived, come see me to pick it up. Thanks!
OR
Press the Enter key and type,write spuds@partya
Then press the Ctrl-D key sequence.Your new tape has just arrived, come see me to pick it up. Thanks!
- Here is an example of
a message sent by the qdaemon daemon:
To reply in the affirmative, enter:Message from mary on trek (tty10) Aug 17 10:03:34 ... Use "write -h 6398492,reply" to reply Please insert tape number 5 into rmt0. <EOT>
Then press the Ctrl-D key sequence.write -h 6398492,ok
To reply in the negative, enter:
Then press the Ctrl-D key sequence.write -h 6398492,cancel
With the -h flag, there is no need to supply the host name or user ID. This information is tracked with the handle.
Files
Item | Description |
---|---|
/etc/hosts | Contains TCP/IP host information. |
/etc/utmp | Contains user and accounting information for the who, write, and login commands. |