my question is
how to pass CTRL+C to run automatic in shell scripting as batch mode
---------- Post updated at 07:46 AM ---------- Previous update was at 07:38 AM ----------
yes this works good if manual on unix
how to do that in shell scriptting as following
1-run command XXX which will not end
2-kill command XXX
u know that shell scripting is a procedural language means every line should be executed and ended so next line can run
in this case i can never go to kill command because the previous line XXX command never ends
Assume you are a shell script, executing. How can you know if you are stuck?
You can only guess. Code for how long you are willing to wait then force an exit.
3600 = number of seconds in one hour
pid=$$
# kill the parent after 3600 seconds
sleep 3600 && kill $pid 2>/dev/null &
child_pid=$!
# [command that runs too long goes here]
sarm pcsp -s
# if sarm completed in less than 3600 seconds you get here
kill $child_pid # stop the child from killing you.
Ctrl+C is equivalent to kill -SIGINT. man kill may tell you what what signal number sigint is on your system. On Debian linux for example its number 2.
In a shellscript you could start the problem process in the background and then kill it after you have your output.
# start the process in the background
sarm pcsp -s CHG_M_P1 &
# store the PID of this process
SARMPID=$!
# here you have to implement something to find out if the process is ready to be killed
# then kill the process
kill -2 $SARMPID