LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-17-2013, 09:51 PM   #1
Juicy
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Rep: Reputation: Disabled
how to stop a bash script by pressing a key?


Hi i want to know how to stop this loop by pressing a key, and if possible how to start it again with a keystroke.

Code:
#!/bin/bash

PORT=$(($RANDOM))


WID=`xdotool search --name "xxxxxxxxx" | head -1`
xdotool windowactivate $WID

while :

 do

 xdotool sleep .$PORT
 xdotool sleep 4
 xdotool type 7


done
 
Old 12-17-2013, 10:19 PM   #2
caladran
LQ Newbie
 
Registered: Dec 2013
Posts: 6

Rep: Reputation: Disabled
Ctrl+Z will stop the process. You can resume it by using the fg command.

In general, a process can be stopped and resumed by sending the SIGSTOP and SIGCONT signals to the process.
 
Old 12-17-2013, 11:30 PM   #3
Juicy
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
naw dude. it doesnt work
 
Old 12-18-2013, 12:18 AM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Yes it does. Unless the xdotool is intercepting signals and ignoring them, which is always possible. IIRC, Ctrl+Z sends SIGTSTP which can be caught by a process and thus ignored, whereas SIGSTOP cannot be caught by a process.
 
Old 12-18-2013, 02:14 AM   #5
Juicy
LQ Newbie
 
Registered: Dec 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
okay so how to i code for it to send sigstop by pressing a key?
 
Old 12-18-2013, 02:48 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,768

Rep: Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887Reputation: 2887
you can use the command stty -a to check how it is set.
you will get something like this:
Code:
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = M-^?; start = ^Q;
stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc ixany imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
see man stty and you will see susp defines that event:
Code:
 susp CHAR
              CHAR will send a terminal stop signal
therefore you need to execute stty susp <your char> if you want to modify it.
 
2 members found this post helpful.
Old 12-18-2013, 09:41 PM   #7
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 12,776
Blog Entries: 17

Rep: Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313Reputation: 3313
Try CTRL-C.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 to end the bash script using commands in bash not manually by pressing ctrl+c Sanpreet Singh Linux - Newbie 1 07-03-2013 02:04 PM
Script to Hit 'Enter' key multiple times in bash script. nithinmp Ubuntu 7 07-19-2012 08:01 AM
How to simulate a ENTER key pressing khaos83 Linux - Newbie 2 08-06-2008 05:41 AM
Blank the screen on pressing key: possible? arrenlex Linux - Software 2 12-26-2005 05:09 PM
Pressing 'alt 1' key twantrd Linux - General 2 01-07-2005 01:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration