0

I am trying to call a script within my bash script which needs Ctrl+c Signal to stop. I need to stop that using Ctrl+c only when I see repeated output behavior from the called Script and then continue with the rest of the script.

FLOW of Script A.sh:
1. environment setup for A.sh
2. call script B.sh
3. If you see repeated behavior in the output pattern of the called script B.sh, send Ctrl+c
4. continue with the rest of script code.
Ataul Haque
  • 93
  • 2
  • 9
  • ctrl-c is not a signal. It is a key sequence which, when executed, sends a SIGINT to the foreground process group. What you want to do is to send an interrupt signal. – William Pursell Nov 06 '17 at 22:38
  • you need `expect` for that. but i would recommend you to use `pexpect` instead, if you speak python. – Jason Hu Nov 06 '17 at 22:40

2 Answers2

1

Afaik, ctrl+C is SIGINT signal. You should be able to use pkill command to send interrupt signal.

pkill -SIGINT B.sh
0

I won't give you the full code for it (you will remember it better if you produce it yourself) but I'll give you the idea..

  1. do your env setup for a.sh
  2. run b.sh and pipe both stdout and stderr to awk..
  3. in awk add every line to a hashmap and increment the counter per insert.. 3.1. check if any of the elements in the hashmap have a value greater than one.. 3.2. if value is greater then one then use a system call to do pkill -SIGINT b.sh
MostWanted
  • 571
  • 1
  • 5
  • 12