1

I was expecting that in rc.local, If say I call program P1 in one line and then P2 in the following line, P2 would only be executed after P1 (on which it depends for successful execution). This is the behavior in bash scripts. However, after booting my machine, P2 was not completed. So my guess is that all commands written in rc.local are run in parallel and P1 did not finish before the execution of P2. I guess this behavior makes sense for daemons...

If it's in parallel, I could just solve this by using the && operator or creating a wrapper script. Still, I would like to confirm the behavior:

In rc.local, commands in new lines are executed sequentially or in parallel?

juanmirocks
  • 113
  • 4

1 Answers1

2

Lines from rc.local are not executed in parallel. It will be executed in the same order like any other bash script.

Don't guess why P2 didn't run, find out for sure by logging its output. For example:

P1 > /tmp/P1.startup 2>&1
P2 > /tmp/P2.startup 2>&1

If P1 has to complete successfully before P2 runs then you will need to set an if true statement. One of these will work:

P1 && \
P2

Or

P1
test $? -eq 0 && P2

Or

P1
if [[ $? == 0 ]]
then
  P2
fi
Gene
  • 3,663
  • 20
  • 39