Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit automatically 3

Status
Not open for further replies.

xsw1971

Programmer
Jun 21, 2001
153
0
0
US
We have a ksh script that allows a user to telnet into a server and run a cycle job. When they log on, the script runs automatically, giving the user a choice of running the job or exiting. When they select exit, the script exits leaving them in the shell so they can start perusing the server.

Is there a way from inside the script to exit completely when they select the exit option, requiring them to log back on?
 
It looks like you are running the script from .profile
So the .profile looks like
Code:
#Some environemnt stuff - path etc
run_script
So when you exit from the script you're left in the shell. If you amend the .profile to look like
Code:
#Some environemnt stuff - path etc
run_script
exit
Then it should work as you want.

Columb Healy
 
Another common option is to EXEC the script. When the script ends, the session ends automatically.

Replace:
run_script
With:
exec run_script
 
exec run_script" will exit only if the "run_script" script ends with the "exit" command. (AFAIK)

Chacal, Inc.[wavey]
 
It shouldn't matter how "run_script" ends. The EXEC should cause the shell to run the new script with the same PID as the shell, so once it ends, there is no parent process to return to. No shell, no function. If the goal is to prevent the user from getting to a shell, then EXEC'ing the script in their .profile should provide that function.

Perhaps my experience has been too limited.
 
In a ksh like scripts you may exit in this manner:
exec kill -9 $PPID

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You may also want to add trap exit 2 15 to the beginning of the .profile so that if they hit Ctrl-C or attempt to kill the process by some other means it still exits.

Annihilannic.
 
Thank to all of you for all the replies! We implemented exec and it works great. We'll look into some of the other tips you guys provided like trap exit 2 15.

Thanks a bunch!
 
If you're using exec then trap is meaningless because the shell process which handles the trap it will no longer exist.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top