LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Sending output messages from a shell script to a Virtual Terminal. (https://www.linuxquestions.org/questions/linux-general-1/sending-output-messages-from-a-shell-script-to-a-virtual-terminal-948441/)

towheedm 06-04-2012 08:55 AM

Sending output messages from a shell script to a Virtual Terminal.
 
I would like to send messages from a shell script to a virtual terminal. This is what I've done. For whatever message I would like outputted, I redirect it to a VT, let's say TTY1:
Code:

echo "Some message goes here" >/dev/tty1
But this gives:
Code:

....../dev/tty1: Permission denied
However, if I log into TTY1 before executing the script, the message is sent there.

Is there a way to send the message to a VT without logging into it first?

Thanks for you help.

pan64 06-04-2012 11:09 AM

If you have not logged into (and noone else logged into) tty1 the terminal does not exist. Actually you are not log into a terminal, but a host and during the login you will get a terminal (let's say the first free will be associated to the login shell). Without login there is no associated terminal, and all the working terminals are associated to another login.
Also you cannot send a message to a tty if noone (or someone else) uses it actually.

Maybe I misunderstood your question, can you please tell me where (to whom) do you want to send message?

towheedm 06-04-2012 12:01 PM

Yeah, I think you misunderstood my question.

Let's say I'm running my script while logged into TTY2. No one is logged into TTY1. So from my script running on TTY2, I want to send messages (whether they be debug, errors or just informational) to TTY1.

Now the TTY's already exists as set up in my inittab:
Code:

1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

And the char devs are for the TTY's are listed in /dev but belong to root.

Now when I try to send a message from TTY2 to TTY1 (remember no one is logged into TTY1):
Code:

echo "my message" >/dev/tty1
I get the permission denied error.

Since I posted, I've checked and found that the error is occurring because the character device tty1 belongs to root and I'm trying to write to it as a normal user.

If I issue the above command as root, the message is printed on TTY1.

Now I realize that I can change the owner of TTY1 to that of the user running the script, send the message to TTY1 and then reset the owner of TTY1 to root. I'm not sure this is the best way security wise. There must be a more elegant solution.


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