ctrl-c in bash script - Programming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ctrl-c in bash script - Programming
# 1  
Old 03-21-2012
ctrl-c in bash script - Programming

Hi All,

I need to place a ctrl-c interrupt in a bash script, there is no other way, it has to be done Smilie

can someone please advise how would I go about this?

i want to use ctrl c in below code, after the code excution of just 1 min or 1sec


Code:
java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2"


how to create the shellscript for above.

Thanks
# 2  
Old 03-21-2012
see the trap command and the SIGINT signal
# 3  
Old 03-21-2012
try this
Code:
# java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2" & pid=$! ; sleep 1 && kill $pid

# 4  
Old 03-21-2012
Quote:
Originally Posted by ygemici
try this
Code:
# java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2" & pid=$! ; sleep 1 && kill $pid

try kill -INT
# 5  
Old 03-21-2012
Looking at this post a your other post on the same subject it seems that the program Cspsamp needs attention if it does not exit properly after completing the query.
Killing a Java client is not good practice because dead connections could accumulate on the server.
# 6  
Old 03-21-2012
i am always executing the above code as it never stop the process automatically so i have to use ctrl c.


As it is my daily executing task so i am planning to add in script

when it executes ,the data writing to a perticular file continuously when the data writing stops but still the process doesnt stop.

here my aim is just wheater i am getting atleast one line data or not. i dont need the complete data.


i need to execute such type of command 10 times in a day.


Thanks

---------- Post updated at 07:27 AM ---------- Previous update was at 07:25 AM ----------

Quote:
Originally Posted by frank_rizzo
see the trap command and the SIGINT signal

i am not getting ,can u plzz explain me in detail


Thanks

---------- Post updated at 07:32 AM ---------- Previous update was at 07:27 AM ----------

Quote:
Originally Posted by ygemici
try this
Code:
# java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2" & pid=$! ; sleep 1 && kill $pid

plz see below code, is this is a right code which u want to say???

but i am unsuccesful in executing the below code.


Code:
 
#! /bin/bash
date1=`date -d "today 08:00:00" +%s`
date2=`date -d "today 08:01:00" +%s`
path=/home/user01/red/IDC/sample
cd $path
java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2"
sleep 2
 
pid=`/bin/ps -fu user01 | /bin/grep "5022=Query|5026=109378|4=627|5=E:VD|" | /bin/grep -v grep| /bin/awk -F' ' '{print $2}'`;

kill $pid;
 
valLaunch=`echo $?`
echo "Value after launch "$valLaunch

# 7  
Old 03-22-2012
Imho. The problem is in the Java program (or the way it is called) because it does not exit after completing the query.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send ctrl-C signal using bash script.

declare -a array=( "LLC-load-misses" "LLC-loads" "LLC-store-misses" "LLC-stores" "branch-load-misses" "branch-loads" "dTLB-load-misses" "dTLB-loads" "dTLB-store-misses" "dTLB-stores" "iTLB-load-misses" "iTLB-loads" "branch-instructions" "branch-misses" "bus-cycles" "cache-misses" "cache-references"... (2 Replies)
Discussion started by: BHASKAR JUPUDI
2 Replies

2. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

3. 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

4. Shell Programming and Scripting

How to handle CTRL+Z or CTRL+C in shells script?

Hi, while executing shell script, in the middle of the process, if we kill the shell script( ctrl+z or ctrl+c), script will be killed and the files which using for the script will be in the folder. How to handle those scenarios. Is there any possibilities, if user breaks the script, I need to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

5. Shell Programming and Scripting

Ctrl-C or Ctrl-Z causing exit the session

H! I have written script where it need to invoke the perl script in background, then write the pid in temp file then bring back the job to foreground. whenever the Ctrl-C or Ctrl-Z is pressed in the script has to exit and prompt should be dispalyed. but this script causing exit from shell session... (2 Replies)
Discussion started by: jramesh1
2 Replies

6. UNIX for Dummies Questions & Answers

ctrl-o in bash on os X leopard -- how does it work exactly?

I'm going through "learning the bash shell" by newham and rosenblatt. I'm trying to ctro-O to execute and then go on to the next command in the history list, ctrl-o again, etc. (I'm just trying to get a feel for it in case I want to use it). But ctrl-o does nothing. Can someone help me out as to... (5 Replies)
Discussion started by: Straitsfan
5 Replies

7. UNIX for Dummies Questions & Answers

alias in bash shell for CTRL + l

Is it possible to create an alias wherein it will use a keystroke. Like to clear the screen in bash i have to use CTRL + l. I want to make an alias 'c' out of this. Thanks. (6 Replies)
Discussion started by: or_knob
6 Replies

8. UNIX for Dummies Questions & Answers

ctrl+S resulting in (i-search) in bash

Hi On solaris, when I press Ctrl+S on an XTERM, the window normally freezes. But today on the same machine, the Ctrl+S key results in (i-search) !! I understand that it has got something to do with emacs (may be not). But I do not use emacs at all. Other specific keys including <backspace>,... (3 Replies)
Discussion started by: balaji280283
3 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Script ctrl+c

How do you make a script so the user can not press ctrl+c and break out of the script? Thanks, :) (1 Reply)
Discussion started by: newtounix
1 Replies
Login or Register to Ask a Question