Disabling ctrl-Z key inside shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Disabling ctrl-Z key inside shell script
# 1  
Old 09-21-2005
Disabling ctrl-Z key inside shell script

Hi
I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key.
How to proceed this? Need reply soon
# 2  
Old 09-21-2005
See Vino's suggestion below (sorry, I was in a rush and in the middle of this and real work)

Last edited by RTM; 09-21-2005 at 09:38 AM..
# 3  
Old 09-21-2005
Quote:
Originally Posted by RTM
Instead of 20, try 24.
Wouldn't this be better off ?

Code:
trap "echo "Ctrl-Z key disabled" SIGTSTP

From solaris signal primer

we have

Code:
SIGTSTP 	24 	Stop 	Stop (job control, e.g., ^z))

And from my linux machine

Code:
$ kill -l SIGTSTP
20
$ kill -l 20
TSTP
$ kill -l TSTP
20
$ kill -l 24
XCPU

vino

Last edited by vino; 09-21-2005 at 09:34 AM..
# 4  
Old 09-21-2005
Tried the following on Solaris (2.6 and 8)
Code:
#!/bin/ksh
trap "" SIGTSTP
echo "try it - should not work"
sleep 15
trap - SIGTSTP
exit

It doesn't work - still allows Control-Z where if I change SIGTSTP to 24, it works. Tried under /bin/sh also.
# 5  
Old 09-21-2005
Tried this on linux and it worked.

Code:
#!/bin/ksh

trap "" TSTP
echo "try it - should not work"
sleep 15
trap - TSTP
exit

signal 24 and SIGTSTP did not work.

It didnt recognize SIGTSTP. Gave me
Code:
./rtm.ksh[3]: trap: bad signal SIGTSTP

And for 24,

Code:
$ ./rtm.ksh  
try it - should not work
[1] + Stopped              ./rtm.ksh 
$ fg
./rtm.ksh

I guess the op has to make the decision for the signal number to be used.

vino
# 6  
Old 09-21-2005
TSTP worked on solaris.
# 7  
Old 09-21-2005
Signals in a shell script become very complex very fast. Notice that the OP complained about using:
trap "`echo "Ctrl-Z key disabled"`" 20
Using the correct quoting is not any better:
trap "echo Cntl-Z key disabled" 20

You guys are proposing:
trap "" 20
which works fine. Whole different stretch of road. Try your scripts using the above trap statement. When you get tried of waiting for them, open another window, locate that sleep process, and do a "kill -CONT" to it.

Control Z is usually the SUSP character. Typing the SUSP characters sends SIGTSTP to all processes in the terminal's foreground process group. To disable control Z, the command is:
stty susp ^-
All of the posts here deal with catching or ignoring the TSTP signal, not disabling Control Z. Remember that shell scripts are collections of processes. The shell uses fork() and exec () to run the sleep program. From the exec man page:
Quote:
The processing of signals by the process is unchanged by exec*(), except that signals caught by the process are set to their default values (see signal(2)).
So when TSTP is ignored, it stays ignored during the execution of the sleep process. But if it was caugth, it goes back to the default action which is to suspend the process. This is bad enough, but what's more, ksh has some bug involving caught job control signals. ksh has it own internal routine to catch those signals. It gets run instead of the specified command. So you don't even get the the message echoed.

I can only curse the darkness. I don't have a candle to light. Sorry.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ctrl-V + Ctrl-J for newline character does not work inside vi editor

Hi friends, I am trying to add a newline char ('\n') between the query and the commit statement in the following shell script. #! /bin/sh echo "select * from tab; commit;" > data.sql I have tried typing in "Ctrl-V + Ctrl-J" combination which has inserted ^@ (NUL) character but the commit... (1 Reply)
Discussion started by: royalibrahim
1 Replies

2. Shell Programming and Scripting

ctrl-c in shell script

The below script has Perl script in it where it gives the usage details. filer.sh echo echo -en "Enter filer : " read filer echo "test.pl -f $filer -F L" Output ========= The following hosts are online and available: Name Total Allocated Used ... (2 Replies)
Discussion started by: nareshkumar522
2 Replies

3. Shell Programming and Scripting

sh: Detect key (CTRL/SHIFT/CAPS LOCK) state?

I'm trying to write a shell script that runs periodically and if I'm not at the keyboard, it should do one thing, but if I am at the keyboard, it should do another thing. Therefore I've decided that it would be good if I could press down the CTRL key, (or some other key) and have the shell script... (8 Replies)
Discussion started by: Ilja
8 Replies

4. Shell Programming and Scripting

How to issue ctrl+D and enter key

My problem is that i have to connect Linux server. I can connect it with SSH but because of the software of the Linux server, i need to press enter and after ctrl+D. Therefore, I need to write a script that should press enter and ctrl+D. How can i write it in KSH shell script. HELP ME! (7 Replies)
Discussion started by: fozay
7 Replies

5. Shell Programming and Scripting

How to catch ENTER key inside the shell script?

Hi, I have a script in which i have to ask user to press the ENTER key to proceed further. can you please help me how can i achive this in my scripting? echo "All the executables builded Successfully " echo " Press Enter to Go Back to the Main Menu" ... (2 Replies)
Discussion started by: plaban.rout
2 Replies

6. UNIX for Advanced & Expert Users

trap ctrl c in shell script

how to trap the ctrl c in unix shell script my script is running in while loop it should not be terminate with ctrl c. if i press ctrl c while running script it shloud ignore the same. please healp.......... thanks in advance (2 Replies)
Discussion started by: arvindng
2 Replies

7. Shell Programming and Scripting

How to delete ctrl key values in a given string?

Hi all, My query is... in the runtime, you are getting any input string. Unfortunately, you have pressed some ctrl keys or esc keys or arrow keys while typing input string. You can get the input value like that... input string as welcome^ So ,I want to remove those unwanted keys... (4 Replies)
Discussion started by: balan_mca
4 Replies

8. Shell Programming and Scripting

writing Enter key inside in shell script

for automating telnet using shell script..... as we enter alphabetic characters inside shell script...how can we do the same for the enter key......Is there any character for the enter key so the enter key need not be pressed manually...... (3 Replies)
Discussion started by: bishweshwar
3 Replies

9. SuSE

Disabling interrupt function of Control-C key combination

I am using informix RDBMS over SUSE LINUX. In linux if you press control-c it acts as an interrupt key. In my program I have used control-c to perform certain functions but it is being overriden by interrupt function of control-c key combination of SUSE LINUX. Kindly suggest me a solution by which... (1 Reply)
Discussion started by: V.V.KUMAR
1 Replies

10. AIX

Disable ctrl-c,ctrl-d,ctrl-d in ksh script

I wrote a ksh script for Helpdesk. I need to know how to disable ctrl-c,ctrl-z,ctrl-d..... so that helpdesk would not be able to get to system prompt :confused: (6 Replies)
Discussion started by: wtofu
6 Replies
Login or Register to Ask a Question