 <p>I'm not sure php is the right tool here. Why not use something that is closer to the shell environment, like a bash script?</p> <p>The only reason I can imagine you want to use PHP is so you can start the process by clicking a link on a page somewhere, and thereby punch a large hole in whatever security your system supposedly has. But if you really must, then it is still easier to write a script in a more shell friendly language and simply use php as a gateway to invoke the script.</p>