ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was hoping maybe someone here could help me though. I use linux at home, no problems, and if I need an extra app or solution, I can just install what I need to get the job done. Here at work, I do not have that luxury.
I need to echo the contents of a file to the screen of a specific person who is logged in. I have no clue how to do this.
EDIT:
I forgot to mention, I do not have a mail server, so I cannot just email myself.
Are you wanting to send the file from somewhere else to the screen or just have the user see the file when they loging?
Doing "cat <file>" displays the contents of a file to the local screen so just adding that to the user's .profile would make it happen on login. (Also you might want to have a look at the "news" command to see if it does what you're really after.)
If you want to send it from somewhere else to a logged in user just do "who". This will show the users with the second column being the tty or pseudo-tty they are on. You can then just redirect your cat to their (pseudo-)tty.
Example:
who returns:
root ttyp0 Dec 29 11:48
ttyp0 is the pseudo-tty (the p lets you know it is pseudo - these are used for network logins rather than direct logins on the console or a serial terminal).
Do "cat file >/dev/ttyp0"
The above requires you do the cat as the root user yourself. If you just want to be able to write messages to a user have a look at the "write" command.
My reasons are odd, I know. I have a cron job set up that writes to a file, then I can just cat or vi the file to see its contents. The cron job runs every 15 minutes and lets me know is an IP address changes or not. If it changes, I need to no as soon as possible. This was the easiest way that I could figure something out without coding a couple of books worth.
I didn't realize you could cat to a pseudo tty. Thats just cool.
Theoretically you don't even have to write to a file. You can setup your cron to output directly to the pty (a short name for pseudo-ttys).
30 18 * * * /mydir/myjob.sh >/dev/ttyp0 2>&1
However: writing to pty is an issue because the pty varies. If you are the first to login you usually get pty 0 but if you're second you'll get pty 1 (if the first is still logged in). If you're 3rd you get pty 2 (if the first two are still logged in) etc... - If either of the first two log out you're apt to get the pty they freed up. Normally you only see the above for messages you want directed to the console (or a specific file) as it doesn't vary.
So long as you're the only person who ever logs in and you only have one window at a time and you always exit cleanly this variability isn't an issue but I wouldn't want to automate a process that did it.
You'd want to script it to do a "who" or "finger" to find if the user you want is on line and get the pty they're using and then cat to that rather than hardcoding a specific pty.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.