1847578 Members
3590 Online
110265 Solutions
New Discussion

to exit a script..

 
SOLVED
Go to solution
someone_4
Honored Contributor

to exit a script..

I have attached a script that I wrote for tech support to check and trouble shoot my sendmail server. The point of this is so that they dont have to know Hp-UX or sendmail and the job can still be done. I created a user in the server that they log into and the script is in the .profile . But what happens is when they exit the script they hit a command line. And then have to type exit. I would like it to where they dont see a command line. And when they do a Q that it will log them off the server. Any ideas?
thanks
9 REPLIES 9
someone_4
Honored Contributor

Re: to exit a script..

One thing I did was put exit in the .profile
The seemed to work unless they did a Cntrl-C
to break out of a running app.
Dan Hetzel
Honored Contributor

Re: to exit a script..

Hi Richard,

You could use
trap "exit 0" INT QUIT ABRT KILL
instead of trap "echo... " 2

Regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
James R. Ferguson
Acclaimed Contributor
Solution

Re: to exit a script..

Hi Richard:

In the $HOME/.profile at the end, do:

exec
When the user exit's your script, they will be logged off. When the user you have created for this purpose logs on, your script will automatically be run. For added protection, at the beginning of the profile, add the following:

trap "" 1 2 3

This will keep the smart user from breaking into a shell as the profile is sourced during the login.

...JRF...
someone_4
Honored Contributor

Re: to exit a script..

no that didnt work. If I am looking at a log
and do cntrl-c to break out it give me a command line.
Dan Hetzel
Honored Contributor

Re: to exit a script..

Hi Richard,

Near the beginning of your script, you could "undefine" the interrupt using:
stty intr ^-

Don't forget to undefine susp and dsusp as well, otherwise job control will still be possible.

Regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Andreas Voss
Honored Contributor

Re: to exit a script..

Hi,

what about putting the script into passwd as the login(shell) ?
BTW: You use 'more' in your script to view mail.log and if more stops for next page the user could get a shell prompt with !

Regards
someone_4
Honored Contributor

Re: to exit a script..

James thanks for your help that worked great!
I was wondering if you could tell me why that works?
James R. Ferguson
Acclaimed Contributor

Re: to exit a script..

Richard:

'exec ' replaces the current shell with a new shell or a program (in your case) without spawning a new process or subshell.

When you exit that exec'ed process, there is nothing to which to return.

The 'trap' command catches the interrupts (signals) we want to handle. As coded, it does nothing, so it serves as a "no-op" to the user, defeating his/her use of the keyboard interrupts during login and for the exec'ed script.

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: to exit a script..

Hi Richard:

BTW : The point that Andreas makes is a very good one! [and you should credit him generously with points!!!]. In the mechanism I presented, it is possible when you use commands like 'more' and 'elm', to invoke a shell from them. As Andreas suggests, an alternative is to replace the usual shell declaration, in the /etc/passwd entry for the user in question, with the name of your script. Then, if the script invokes 'more', for instance, to invoke a shell, the user will be rewarded merely with yet another instantiation of your script! Once your script is exited, the user will be logged off with either this mechanism, or the one I suggestsed originally.

Regards!

...JRF...