LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-29-2005, 10:04 AM   #1
mpgram
Member
 
Registered: Sep 2003
Location: Dallas TX
Distribution: Red Hat
Posts: 59

Rep: Reputation: 15
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.

EDIT:
I forgot to mention, I do not have a mail server, so I cannot just email myself.
 
Old 12-29-2005, 10:52 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 12-29-2005, 12:13 PM   #3
mpgram
Member
 
Registered: Sep 2003
Location: Dallas TX
Distribution: Red Hat
Posts: 59

Original Poster
Rep: Reputation: 15
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.
 
Old 12-29-2005, 12:24 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Three ksh scripting questions liguorir Linux - Software 2 10-22-2005 12:40 PM
Case Statement With Aix Ksh Scripting ']['HeBroken AIX 2 02-09-2005 12:44 PM
How to install Ksh shell hardeep_ubhi Linux - Newbie 1 02-03-2005 07:55 AM
KSH Scripting case statement..... ']['HeBroken Programming 1 12-10-2004 10:38 AM
some ksh scripting nabil Programming 1 03-03-2002 10:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration