Problems in running a script as a daemon at startup
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
A very simple technique that I have used is to simply code your endless loop functionality into a second script or executable. From within the primary script that is run during init you invoke (execute) the second script as a background program ie "/bin/sh second_script.sh &". This will cause the primary script to fork/exec the secondary script while the primary script runs to completion and terminates properly.
As oblivious69 pointed out in post 3 of this thread, the script never increments $lab so the test $lab="1" is always true (after substitution it is "1=1" which is a non-empty string so always tests true) and the loop never completes.
Even if you changed $lab in the loop it would never exit because the equality operator = must have spaces on either side.