Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 06-04-2012, 09:55 AM   #1
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
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:
echo "Some message goes here" >/dev/tty1
But this gives:
....../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.
Old 06-04-2012, 12:09 PM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,988

Rep: Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290Reputation: 5290
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?
Old 06-04-2012, 01:01 PM   #3
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Original Poster
Rep: Reputation: 125Reputation: 125
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:
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):
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
copy/paste output from shell (not terminal) bluegospel Linux - Newbie 13 07-21-2010 02:37 PM
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 01:46 PM
Stop syslogd from sending messages to root terminal ddc441 Fedora 8 03-26-2009 06:15 PM
Bash script question (sending output to specific lines) ptcl Linux - Software 9 11-21-2006 04:53 AM
Shell script sending mail mfrick Linux - General 5 09-01-2005 08:46 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:07 AM.

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