passing a variable from php to bash

前端 未结 2 1193
一整个雨季
一整个雨季 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 11:52

    Got it.

    <?php
    $upassword = 'test1234'; $uaddress = 'mytestuser@tpcmedia.com';
    $uaddress = escapeshellarg($uaddress);
    $upassword = escapeshellarg($upassword);
    $addr = shell_exec("sudo /home/tpcmedia/cgi-bin/member_add_postfixadmin $uaddress $upassword 2>&1");
    ?>
    
    
    #!/bin/bash -x
    uaddress=$1
    upassword=$2
    ssh -p 2222 -6 2400:8900::f03c:91ff:fe69:8aaf "/var/www/localhost/htdocs/postfixadmin/scripts/postfixadmin-cli mailbox add" $uaddress --password $upassword --password2 $upassword
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题