PHPでbashスクリプトを実行する方法

PHPでbashスクリプトを実行する方法

Bashスクリプトを実行するには、次のPHPファイルがあります...

<?php
    
    $old_path = getcwd();
    chdir('/home/scripts/');
    $var = escapeshellarg("PC7");
    $output = shell_exec("./Script2.sh $var");
    chdir($old_path);
    echo $output;
    
 ?>

ここに私のScript2.shファイルがあります。

 #!/bin/bash
    
    var=$1
    
    if [ "$var" == "PC7" ]; then
        echo "Strings are equal"
    else
        echo "Strings are not equal"
    fi

これで、ボタンをクリックしたときに実行されるようにPHP関数でこれを使用する必要があります。ここに私の試みがあります。しかし、私はUpdated successfully- Strings are equal出力を得ません。私がここで何か間違っているのでしょうか?

<input type="button" style="background-color:#00BFFF;padding:3px;border: none;"  class="button" name="pc7" value="Get The Latest"/>


$(document).ready(function(){
      $('.button').click(function(){
        var clickBtnValue = $(this).attr('name');
        var ajaxurl = 'runscripts_intvoice.php',
        data =  {'action': clickBtnValue};
        $.post(ajaxurl, data, function (response) {
            // Response div goes here.
            
            alert("Updated successfully -"+response);

        });
        
       
    });

});

ベストアンサー1

おすすめ記事