Do you have suggestions how to write a script which detects whether the user specified at the first parameter of the script is logged?
If you are logged on, offer him the opportunity to write a message to the user. Subsequently, as the message sent will be offered the opportunity to write another report or completing the work of the script.
In the case of not user is logged on and the message "" is unknown ...
Thanks.
Now to send messages to all users, use the wall command, it comes pre-installed in all Linux Distributions which will allow us to send messages to another user in the terminal using tty2. You can use any symbol, character, or white space in the message.
The wall command (as in "write all") allows you to send a message to all users who are currently logged into the system.
Broadcasting a Message To see all the logged-in users, run the w or who command. The wall command will wait for you to enter text. When you're done typing the message, press Ctrl+D to end the program and broadcast the message.
'write' is one of the solution. Run command who
who
the output will be something like
nand pts/1 2013-11-20 11:59 (:0) nand pts/7 2013-11-20 13:09 (:0)
Now you can message to user "nand" on pts/1 using write as
write nand pts/1
Press enter after writing this command then type any message you want to send, the other user will see the output as
Message from nand@mypc on pts/19 at 14:54 ... hi hi hello
In Linux everything is treated as file system, Each terminal has its file that can seen by who
command.
Eg:
> who
Output:
username tty7 2016-01-08 10:36 (:0)
username pts/0 2016-01-08 12:56 (:0.0)
username pts/1 2016-01-08 16:05 (:0.0)
username pts/2 2016-01-08 17:10 (:0.0)
Here username pts/0
is special file for 1st terminal(2nd line in output). Data written to this special file will be displayed 1st terminal
Eg:
> write username pts/0
Note: to exit from typing message, use Ctrl+z.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With