I have a situation, where some script (running background) need to use the 'write' command and get a text to appeared on any screen of some particular user.
Like:
>echo "$message"|write user1
But I surprisingly realized, that if a person logged under any other name and after that uses the 'su' command to log in as the 'user1', he will not be reachable by the 'write' command!
Is there any other way to send a message to anyone who currently logged as 'user1', even by 'su'?
Hi,
The write program writes text to a users tty. That is what the OP was talking about.
Yo should use the who command to figure out what terminal/xterm/whatever tty the user is using. The root user more often than not has messaging turned off by default. Use the mesg command to configure those rules.
And have a look at "man write" and "man mesg"
/Lakris
EDIT:
sorry, I guess I got carried away... I usually do an "ssh -X user@localhost" because I'm lazy and want X-forwarding, and then I always get a clean and obvious login. su'd users don't show up in who. So, I would find a way , with for example ps axjf to find the user You want to reach, find the tty, and find the owner of that tty...
this is very crude but I guess You get the idea...
It is not a solution to my situation - to have anything appeares on user's loggin!
First - I need it displayed right away (assuming, someone use that log name - user1 - in every given point of time)
Second - the 'user1' is not logging on - someone uses 'su' to use that account for some tasks!
The 'write' command perfectly works out what I need - it is showing a message on first found screen (tty) for a requested user, BUT it is fooled by the 'su' loggin.
Whell, it is a production control task that should inform about itself in some condition.
And you can guess, in different time different people performe 'production control' duties.
I do not need to have it write for a particular individual, but to an anyone who currently use the production control loggin 'user1'.
Great, glad to help.
And You can refine Your script by checking for return values of the "ps axfj" just to see if there is a grok (or user1) su'd to write to and take proper action.
I am still not able to resolve this issue.
I am on SunOS 5.6 (I guess the "ps axfj" is on Linux) and 'ps' do not shows a tree, where I can find the 'su' usage (or I did not find a way; so, advise will be appreciated.)
Is there, on Sun UNIX, a way to figured it out who was used the 'su'?
I see the 'su' is logget in one special file - /var/adm/sulog, but it owned by 'root' and has only owner 'resd' permission.
Is there any way or utilite to read it or just to get who is logged bu 'su' command by any other way?
Ok, for one thing You can have a look at the non-BSD style of options for ps, so ps axfj would amount to ps -ejH, or something.
And I had a look at my box (yes, it's GNU/Linux) and it logs su actions in /var/log/auth.log. Maybe You have something similar.
Example, if I su to grok this will appear in the file:
Feb 4 00:42:01 landet su[6742]: + pts/1 lakris:grok
there can of course be several such lines, figure out which one is current.
And to write to the user su'd in as grok, use
Ok, well, if You can't read the log files, I guess You will just have to go back to examining output from ps, use man ps and google to find how You can extract info about who su'd to a specific user (parameters to ps) , info on parent process and who owns it.