kingsmasher1 kingsmasher1 - 1 year ago 84
Linux Question

Invoking subshells from script does not work if run in background

I have a script running in background, like:

su - insite1 -c "" &

Now this script, has contents:

while [ 1 ]
echo "Hello World from invokeTest" >> /tmp/invokeTest
( exec "/tmp/" )

Although it prints, "Hello World from invokeTest" it does not call

My question:
Is there any way to call in infinite while loop directly from
su - insite1 -c" "
so that we can totally skip
itself (but needs to run in background"?

If no, how to make sure is called from

Answer Source

To answer your question about running the command without a script, you can put any shell commands into the -c argument, including a while loop. So you can write:

su - insite1 -c 'while :; do echo "Hello World" >> /tmp/invokeTest; /tmp/; done' &
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download