我有下面的 php 文件来运行 bash 脚本......
<?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);
});
});
});