Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I wrote a bash script that logs keycodes in a simple file. I have put the code in a while loop because I want it to log continuosly. But if I run the bash script in the terminal, the cursor just keeps blinking suggesting that the file is indeed caught in an infinte loop. Now i want to be able to quit this loop gracefully. I don't know how. Ctrl+C won't work. I just close the terminal and force quit the process. How do i break out of the while loop as and when the user feels like quitting the program?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

If you get a blinking cursor you are probably not actually in a loop. You are probably expecting input. Try Ctrl+D. If that doesn't work then open a new terminal and ps aux | grep command where command is the name of the script you wrote and then kill the pid that is returned.

share|improve this answer
    
The cursor stops blinking after some time, so i know there is a loop going on. I want this script to run on startup. I want to stop the bash script by passing a flag like bash logger.sh -stop and if i want it to start again it should be something like bash logger.sh -start How do i go about this? –  Vivek Pradhan Jan 22 '13 at 7:43
    
upstart.ubuntu.com/cookbook is a good start, but I can not answer your question directly. You need to find a way to stop all your processing smoothly and use that in the stop hook. –  coteyr Jan 22 '13 at 14:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.