I've a little problem, probably it's a stupid question, but I started learning bash about a week ago... I have 2 script, a.sh and b.sh. I need to make both running constantly. b.sh should waits for a signal from a.sh
(I'm trying to explain: a.sh and b.sh run --> a.sh sends a signal to b.sh -> b.sh traps signal, does something --> a.sh does something else and then sends another signal --> b.sh traps signal, does something --> etc.)
This is what I've tried:
a.sh:
#!/bin/bash
./b.sh &;
bpid=$!;
# do something.....
while true
do
#do something....
if [ condition ]
then
kill -SIGUSR1 $bpid;
fi
done
b.sh:
#!/bin/bash
while true
do
trap "echo I'm here;" SIGUSR1;
done
When I run a.sh I get no output from b.sh, even if I redirect the standard output to a file... However, when I run b.sh in background from my bash shell, it seems to answer to my SIGUSR1 (sent with the same command, directly from shell) (I'm getting the right output) What I'm missing?
EDIT: this is a simple example that I'm trying to run:
a.sh:
#!/bin/bash
./b.sh &
lastpid=$!;
if [ "$1" == "something" ]
then
kill -SIGUSR1 $lastpid;
fi
b.sh:
#!/bin/bash
trap "echo testlog 1>temp" SIGUSR1;
while true
do
wait
done
I can't get the file "temp" when running a.sh.
However if I execute ./b.sh &
and then kill -SIGUSR1 PIDOFB
manually, everything working fine...
One of the possible solutions would be the next one (perhaps, it's dirty one, but it works):
a.sh:
b.sh:
The idea is to simply write down a PID value from within a b (background) script and read it from the a (main) script.