Well I'm lost. I just can't see any error or flaw.
Here is how I read the shell :
Line 1 : remove the file called OK
Line 2 : replace eval in the file exec.php with safeeval in a file called tmp, and then creating a file called OK
Line 3 : if a file called OK exists, proceed
Line 4 : remove exec.php ; rename tmp and call it exec.php
Line 5 : end if
I don't have any Unix machine and cannot test the shell, but it should be working, right ? Aside from some quotes that I'd replace with strongs ('), and the -E command that seems useless, that looks legit.
Maybe the -E is a hint that could lead us to think that there is something ELSE to be fixed in the .php file (and indeed, the PHP script seems very odd. If cmd2 is empty, then eval() it ? eval the empty string ??!)
Any hint very welcome


