I have the following test script that does not behave as I would expect when I try starting it at boot. My overall script is larger, but this is the essence of the issue at hand. What it is doing is turning on a light (just to verify the script is running), waiting a few seconds, starting a co-process for linphonec, a CLI based SIP phone client, and then sends the "call" command to the co-process for linphone to dial (my cell number replaced with a fake number).
Code:
#!/bin/bash
#Turn on the LED Light
gpio mode 3 out
gpio write 3 1
#sleep
sleep 5
#Intial coproc startup for Linphonec
coproc linphonec
sleep 4
echo "call 5555555555" >&"${COPROC[1]}"
while true
do
#[DOES OTHER STUFF HERE]
sleep 0.05
done
I am running this on Raspian as a root user. If I run this from a putty CLI, it works as expected, But my goal is for the script to start at boot. If I put the following in the rc.local and reboot:
Code:
/usr/local/bin/test.sh &
I see that both the script and linphonec are running:
Code:
root 1936 1 0 15:26 ? 00:00:00 /bin/bash /usr/local/bin/test.sh
root 2016 1936 1 15:26 ? 00:00:00 linphonec
The script turns on the light, but the call does not get placed. I am wondering if this has to do with coproc and how it works? I have also tried putting it in a CRON job to start as shown below with the same results:
Code:
SHELL=/bin/bash
@reboot /bin/sleep 10 ; /usr/local/bin/test.sh &
The light will turn on, but no call. It is interesting to note that if I kill the script process using "kill", the linphonec process is not killed. If I terminate the process while it is running in a putty terminal using ctrl-c, both processes are stopped.
So how can I get this script to operate correctly at startup? I am sure it has something to do with shells and how they behave, but I do not know much about this.