Operating System - HP-UX
1833758 Members
2841 Online
110063 Solutions
New Discussion

need tty settings in startup script

 
Peter Kielbasiewicz
Frequent Advisor

need tty settings in startup script

I have a startup script for a process which runs ok when I invoke it from a regular shell but when it is called at boot time it fails to run correctly.
In syslog it shows a message tty??.
In fact I need to set stty intr "^C" before starting the process as it inherits this setting from its invoking process.
Unfortunately I do not have a tty at boot time.
How can I bind a pseudo tty to the startup script so that I can do some stty settings before I start my program?
5 REPLIES 5
Sanjay Kumar Suri
Honored Contributor

Re: need tty settings in startup script

Will the following help?

set the shell to be used in the script itself.

#!/usr/bin/csh

and then set stty intr "^C"

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Rodney Hills
Honored Contributor

Re: need tty settings in startup script

If you have a specific terminal device like /dev/tty03, then you could do-

stty intr "^C"
If you would like to set it for all new terminal connections, then use device /dev/ttyconf. example-

stty intr "^C"
Then all new terminal connections (except /dev/console) will have that intr set to ^C.

Note- If you reboot your system, you must run stty again. See "man stty" for more info.

HTH

-- Rod Hills
There be dragons...
Steve Steel
Honored Contributor

Re: need tty settings in startup script

Hi

stty needs a controlling tty and there is no good way to do this.

You need to set this when you run your process

Then it will be ok

Make an alias unisg #!/bin/sh
processname="stty intr \"^C\";/a/b/c/procssname"

Then typing processname will do both

Steve STeel
If you want truly to understand something, try to change it. (Kurt Lewin)
A. Clay Stephenson
Acclaimed Contributor

Re: need tty settings in startup script

While it is relatively easy to run a stty using an arbitrary device as stdin, running this stty does nothing to actually send a SIGINT to this process. In general, processes started by rc and not associated with a controlling terminal. Moreover, if they are, you will now need to worry about SIGHUP.

I suspect the better approach is to modify your script no to require interactive commands.

e.g.

if [ -t 0 ]
then
stty ...
tset ...
tabs ...
fi

Only when stdin is a tty device will the commands be executed. If you are doing something in your rc script like su - someuser .... then change your script to explicitly set env vars and simply invoke as su someuser ... so that the .profile is not used. Ideally both someuser's .profile AND your script would source the same file via the "." (dot) shell operator to set any needed environment variables.

If it ain't broke, I can fix that.
Peter Kielbasiewicz
Frequent Advisor

Re: need tty settings in startup script

My script is the openssh daemon which is started at boot time to handle ssh session requests.
Unfortunately there is a problem on HPUX 10.20 that the sshd inherits the intr setting at startup time and it can not be set again from within an ssh connection!

Thus if stty intr "^C" was not defined at sshd start no ssh client can use Ctrl-C and client sessions can not interrupt any command.

As there is no stty associated to the rc script I am looking for a way to set 'intr' before the daemon is started so that it accepts Ctrl-C correctly.