LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-18-2012, 05:02 PM   #1
kelso.b
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
Trap a user in a shell script


My situation is similar to the one outlined here, but I don't want the user to be able to log out either.

Basically I want this terminal to always be running this application. I have it running on startup (using tty1.conf to auto-login, .profile to launch the app). But if the user kills the application (ctrl-c), I want it to start up again.

I know it's possible to do on FreeBSD using gettytab, but I'm not sure how it would be done on linux (Ubuntu 11.10 Server). A nice thing about the BSD method was that you could escape the trap using Alt+F7, bringing you to a shell.

Last edited by kelso.b; 04-18-2012 at 05:04 PM.
 
Old 04-18-2012, 06:52 PM   #2
ShadowCat8
Member
 
Registered: Nov 2004
Location: San Bernardino, CA
Distribution: Gentoo, Arch, (RedHat4.x-9.x, FedoraCore 1.x-4.x, Debian Potato-Sarge, LFS 6.0, etc.)
Posts: 261

Rep: Reputation: 52
Greetings,

Well, I know that the equivalent to FreeBSD's getty is agetty in linux, though, as the man page states:
Quote:
Originally Posted by The agetty man page
This program does not use the /etc/gettydefs (System V) or /etc/gettytab (SunOS 4) files.
Now, I have a couple questions about this:
  1. This application will be running on that terminal, no matter what happens with the rest of the system?
  2. Will there be an actual user login, or are you going to force a specific non-privileged account to login without a password?
  3. What is expected to happen to the terminal and/or app that's running in it when the system receives the 'shutdown' or 'reboot' (or any equivalent) commands?

HTH. Let us know.
 
Old 04-18-2012, 07:15 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you look at /etc/inittab, you can see how login or gdm are started & respawned. But why isn't it started as a service?

Also, inittab may go away after systemd is used exclusively.
 
Old 04-18-2012, 07:34 PM   #4
kelso.b
LQ Newbie
 
Registered: Apr 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
This application will be running on that terminal, no matter what happens with the rest of the system?
Yes, it is supposed to be a single-purpose terminal for running only that application.

Quote:
Will there be an actual user login, or are you going to force a specific non-privileged account to login without a password?
I'm currently doing a forced login on an unprivileged account using /etc/tty1.conf

Quote:
What is expected to happen to the terminal and/or app that's running in it when the system receives the 'shutdown' or 'reboot' (or any equivalent) commands?
Those are fine; I don't expect the script to prevent shutdown or anything. Just needs to start back up when the system restarts.
 
Old 04-20-2012, 11:21 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Try stty -isig in your script to disable SIGINT, SIGQUIT, and SIGSTOP from key bindings.
Kevin Barry
 
Old 04-20-2012, 11:35 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
you can start it also in the background
 
Old 04-20-2012, 11:54 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
you can start it also in the background
Assuming the terminal is actually needed for interaction, the process will sleep if it tries to read from the terminal until it's in the foreground.
Kevin Barry
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i change to super user then revert back to ordinary user ,using shell script? wrapster Solaris / OpenSolaris 6 03-18-2009 03:37 AM
Shell Scripting -- Trap Weirdness mudd1 Programming 9 11-05-2007 05:03 AM
Shell script trap and log out a user fmcauley Programming 6 03-06-2007 10:10 PM
Shell script that changes user davholla Linux - General 2 03-23-2004 09:18 PM
shell script - trap program termination dnijaguar Linux - Software 0 07-19-2003 12:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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