Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to redirect my serial port while telnet session in linux.

I have an embedded Linux box which is has a serial console. After I do a telnet to the box, I can type in both the serial console as well as the telnet console. I want to stop the serial console access or redirect it to something else. After I exit from the telnet console, I should be able to access the serial console again. Can any one suggest, please?

I have planned to put cat /dev/console > /dev/ttyp0 when telnet session starts. It solves the problem of not accessing the serial console when telnet session console is open, but when I exit from the telnet console and type something on the serial console, for the shell command -/bin/sh: command not found (Shell not running perhaps?).

Thanks.

share|improve this question
    
I'm not sure I understand this properly? Are you saying that you want to see the kernel messages (that only go to the console) repeated in the telnet session. Or are you saying that you want to shut down serial access (some sort of privacy thing?) while you're using telnet? –  ams Aug 28 '12 at 12:15
    
@ams Yes, the second one ("you want to shut down serial access (some sort of privacy thing?) while you're using telnet?") is what I want. –  user22638 Aug 28 '12 at 12:19
add comment

1 Answer 1

Each console has a process associated with it. You can usually find them on the process list easily enough. On Ubuntu it is called getty or agetty. On other systems it might be login, or it could just be a shell process.

All you have to do is disable that process to shut down the serial port. You can't kill it because init will just spawn a fresh one, but you could pause it:

kill -STOP <pid>

Where you find <pid> with ps.

Then, when you want to reenable it, you restart it:

kill -CONT <pid>

Or, if you want it to start afresh, kill it and let the respawn happen:

kill -KILL <pid>

Of course, you have to remember to restart it before leaving telnet. If you want something more fool-proof, it depends what utilities your system has. If you have cron then you could set up something that checks if telnet has gone (since it last looked) and restarts the serial terminal. It would be a bit tricky, but possible. If you don't have cron then start some sort of background process that wakes up on SIGHUP and does the restart. That's probably even more tricky.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.