Must raise my old question again - script seems NOT to run in background. What could be wrong?

I run remote bash script from my PHP script:
system("nohup /blabla/myscript 'Mail subject' results@from.this_person http://www/result_folder /blabla/slow_script param1 param2 param3 param4 &")

'myscript' waits for result, generated by 'slow_script' (it's a link to file) and sends it to the given e-mail address. If slow_script get data, that does not require computation (wrong input data, etc) - everything works ok.
BUT if it works slow - I can see, that BACKGROUND doesn't work here, because PHP script 'hangs' - i.e. waits until 'myscript' completes execution :(

For the information: 'myscript' contains such string: filename=`${*:5}`, filename in the given case is the result of 'slow_script'. Maybe it's wrong to write so? Otherwise I can't see the problem.

Please, help.
Who is Participating?
I found an error. Your php keeps running until there are open file descriptors passed to your shell scripts.
Try this sintax:
system("nohup /blabla/myscript 'Mail subject' results@from.this_person http://www/result_folder /blabla/slow_script param1 param2 param3 param4 0<&- 1<&- 2<&- &")

Now your shell script will be called without stdin/strout/stderr, however you will not see nohup.out there.
Hello, Nafigator, I remember your question.
I've just tested very simple script:

sleep 6000

system("nohup /tmp/ &");
print "OK";

php /tmp/runme.php

that works fine, runme.php exited and is  still running.
I see no problems, php shouldn't 'hang' on that command, but myscript may hang as long as it likes.

You may have a problem, if you are using stdin or stdout inside your scripts,  stdin/out are the same as in php script.

Also I see no problems with `${*:5}`. It may be problem if any of 'params' have spaces.

How to debug? Add '-x' flag to your myscript header:
#!/bin/bash -x

then read nohup.out file

NafigatorAuthor Commented:
Arty, thanks a lot for advice, I suppose that answer is very close, but still not here. I now have nohup.out file, while my web script 'hangs' on execution and...
nohup says that

/blabla/slow_script: line XX: 16465 Terminated
and next line gives such line:
$GMC_DIR/gmc -n1$file1 $ch1_arg -n2$file2 $ch2_arg >out_table 2>err

where gmc === "myscript" from my previous letter

I wonder, why slow script was actually terminated... It creates folder inside of resulf folder (that has write access set for all users), where it places the results, and even writes one zero-length file ("out_table") there now. But it must create a set of result files there, filled with data (if input files are "valid" - and they are).
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

NafigatorAuthor Commented:
Sorry, I misinformed you.
nohup.out was an old one - it was created when i tried to run my PHP line from ssh console yesterday.
So, after I run this line I got message saying that process has been sent to background, but I didn't know how to get back to command-line again, so I CTRL-C'ed it. That's where the message '...Terminated' is from.

About testing today -
ok, later, after out_table, all rest needed files have been created... And link has been received. But I had to terminate my web-script as it hung up. That means, that execution is NOT performed in background, everything the rest is allright...
BTW - I deleted nohup.out, run web script again now - it hangs as usually, but new nohup.out is not being created, although I added -x flag to myscript...
But I had to terminate my web-script as it hung up.

What is a 'web-script':
- php?
- that script that was called from php?
- slow_script?

nohup.out is created in current working directory if you have permissions to write to. When you go to different directory and run your php script, you may not see nohup.out there.
NafigatorAuthor Commented:
web-script is written in php, it uses line: system("nohup /.../gmc 'Mail subject' results@from.this_person http://www/result_folder /blabla/slow_script param1 param2 param3 param4 &")
to run my bash script "gmc" in background mode.

"slow_script" is bash script or perl script (sorry, not sure. It's written by another person and seems to work correct itself).
It takes 4 arguments (param1...param4) to transfer them to another thing (Java or something) - I may investigate, what's exactly there: I just thought that problem was on my side and thus was never interested - and sends me the result, that is URL to result file.

"gmc" script calls slow_script with param1...param4 by:
Then it calls "sendmailer" bash script (written by me - it's almost a usual sendmail, but takes parameters of sender mail, addressee mail, body in HTML format), that sends "http://www/result_folder/filename" URL to the ""
NafigatorAuthor Commented:
Works flawlessly. Thanks a lot!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.