-   Programming (
-   -   KSH and SCO Shell Scripting (

mpgram 12-29-2005 10:04 AM

KSH and SCO Shell Scripting
I know, I know, SCO is not Linux...

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.

I forgot to mention, I do not have a mail server, so I cannot just email myself.

MensaWater 12-29-2005 10:52 AM

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.

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.

mpgram 12-29-2005 12:13 PM

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.

Thanks for the help.

MensaWater 12-29-2005 12:24 PM

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/ >/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.

All times are GMT -5. The time now is 05:25 PM.