0

I have a PHP script that will be run as cron on Ubuntu server.

I am trying to execute a bash script from PHP script like this :

    exec(escapeshellarg('/bin/bash ') . escapeshellarg("/home/monu/myBash.sh") . escapeshellarg("var1") . escapeshellarg("var2") .escapeshellarg("var3"));

When I run "php myPHP.php" in terminal as user (monu) then I get error like this :

    sh: 1: /bin/bash /home/monu/myBash.sh var1 var2 var3: not found

The contents of myBash.sh are something like :

    export CLASSPATH=./:./lib/xp.jar:./lib/ojdbc14.jar:./lib/log4j-1.2.8.jar:./lib/log4j.properties:./lib/log4j.xml

    cd someDir
    ./install.sh $A $B $C $D
    cd ..

When I manually execute the BASH script from command line it works as expected.

I've even tried system() and shell_exec() but still no luck.

How should I call this BASH script from PHP script to make it work, any hints ?

4

1 回答 1

1

escapeshellarg() should be used on each argument, not the command as a whole.

exec(escapeshellarg('/bin/bash') . ' ' . escapeshellarg("/home/monu/myBash.sh") . ' ' . escapeshellarg(...));
于 2013-06-16T21:01:48.703 回答