passing a variable from php to bash

前端 未结 2 1201
一整个雨季
一整个雨季 2020-12-18 11:18

I cannot seem to get a variable passed to my bash script from php. $uaddress and $upassword come up empty no matter what I try.

******<

2条回答
  •  醉话见心
    2020-12-18 12:01

    You need to pass the variables as arguments to the shell script, and the shell script has to read its arguments.

    So in PHP:

    $useraddress = escapeshellarg('mytestuser@tpccmedia.com');
    $upassword = escapeshellarg('test1234');
    $addr = shell_exec("sudo /home/tpccmedia/cgi-bin/member_add_postfixadmin $useraddress $upassword 2>&1");
    

    and in the shell script:

    useraddress=$1
    upassword=$2
    

提交回复
热议问题