Getting cntrl-c entered inside a ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting cntrl-c entered inside a ksh script
# 1  
Old 01-06-2010
Getting cntrl-c entered inside a ksh script

hi guys,

my ksh script is calling another script. The other script expects user to press CNTR-C, and does not return to the prompt.

in my script, I want to call the other script, but somehow don't want it to wait forever, I want to return to my script.

e.g.

script2.ksh outputs:

"No name found; please enter a name"
Please enter a name if you want to continue


and it does not return until we either enter a name or press control-c.

but in script1.ksh, I want to run script2.ksh, and do a grep to see if it displays "No name found", and then continue. But because script2 does not exit until you enter a name and press return or control-c, I cannot do anything!

thanks
# 2  
Old 01-06-2010
You could background it, wait a few seconds, and send it SIGINT with the kill command, terminating it like a ctrl-c. Or you could redirect a newline into its standard input, if a blank name will do. Or you could redirect /dev/null into its standard input, which will cause the read to instantly EOF instead of waiting, if the script can handle a failed read properly.

Last edited by Corona688; 01-06-2010 at 12:08 PM..
# 3  
Old 01-06-2010
Quote:
Originally Posted by Corona688
You could background it, wait a few seconds, and send it SIGINT with the kill command, terminating it like a ctrl-c. Or you could redirect a newline into its standard input, if a blank name will do. Or you could redirect /dev/null into its standard input, which will cause the read to instantly EOF instead of waiting, if the script can handle a failed read properly.
wonderful - thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

2. Shell Programming and Scripting

Using Sed to do a substitution inside ksh

I'm trying to do an ls from inside of a ksh script. I loop through the results one line at a time and attempt to do a substitution using sed to convert YYYYMMDD from the older files into the newer files. Basically sometimes the ETL load runs over midnight and half the files are off by one day... (3 Replies)
Discussion started by: Calbrenar
3 Replies

3. Shell Programming and Scripting

How to continue script if right word is not entered?

Hello, I am writing a script and in this script, I want to be able to have the script continue running if the correct word is not entered... Here is an excerpt from me script: read request if ; then echo "You have asked for the System Temperature..." cat... (1 Reply)
Discussion started by: niconico96
1 Replies

4. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

5. Shell Programming and Scripting

Prompt for 2 variables if nothing is entered end script

What I'm trying to do is write a bash file that prompts for the user's name and what the want to name the output file. If nothing is entered in either prompt the script must end and not create the output file. This is what I have so far: #!/bin/sh echo "What is your name?" read NAME if ... (4 Replies)
Discussion started by: kriminul1982
4 Replies

6. Shell Programming and Scripting

Using telnet inside a ksh

Hello, i am trying to use telnet inside of a ksh script. i would like to do like the following: #!/bin/ksh ... user="user" hostname="hostname" telnet -l $user $hostname |& wait #end of the ksh and with this piece of code, i would like to telnet another machine, and let the user use... (4 Replies)
Discussion started by: Jidma
4 Replies

7. Shell Programming and Scripting

Using Perl Inside KSH

Hi there, I am new to Perl and KSH. The system I am using picks up the KSH scripts and uses them in a batch job control system. I am trying to set a variable from a perl command #!/bin/ksh -eaxp #******************************************************************************* # Testing... (5 Replies)
Discussion started by: SaadLive
5 Replies

8. Shell Programming and Scripting

Exit statement ignored inside KSH function

Hi All, I have multiple functions in my script and I'm trying to capture stdout from some of them, but I also do some error checking in them (in the functions that output something to their stdout that needs capturing) and I need to be able to end the entire script with an error message. ... (2 Replies)
Discussion started by: gkubok
2 Replies

9. Shell Programming and Scripting

expr inside a ksh script Solaris

Hi; If I do something like this. dftotalsize=0;export dftotalsize;df -k | grep \/db001 | awk '{print $4}' | while read theinput \ ; do export $theinput; dftotalsize=`expr $dftotalsize + $theinput`; export dftotalsize; echo $dftotalsize; done ; echo `expr $dftotalsize \/ 1024 \/ 1024 "GB" Is... (4 Replies)
Discussion started by: myjess
4 Replies

10. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies
Login or Register to Ask a Question