命令中的语法错误

时间:2013-10-03 01:25:15

标签: javascript php shell shell-exec

我有一个iframe,当用户点击按钮时,从控制面板发送命令。使用下面的代码,当用户点击时按钮没有任何反应,因为代码中存在语法错误。

$items['googledotcom'] = array
        (
            'description'=>'DNS resolution test',
            '1'=>1,
            '0'=>0,
            'fixCommand'=>'EXC service network restart; echo "nameserver 8.8.8.8" >> /etc/resolv.conf; sleep 10; health check',
        );

上述代码不起作用,因为这一行: echo“nameserver 8.8.8.8”>> /etc/resolv.conf中;

但是当我删除上面的代码时代码会起作用。但我也需要添加上面一行。

有关语法的任何建议吗?

谢谢!

更新

命令格式: enter image description here

doCommand Javascript:

<script type='text/javascript'>

function doCommand(command)
{
    var r=confirm("Are you sure you want to \"" + command + "\"");
    if (!r)
    {
        return;
    }

    $.post('/device/commands-frame/', { id : '<?=$this->site->id;?>', act : command, command : command }, function(data)
    {
        alert('Command has been sent');
    });
}
</script>

1 个答案:

答案 0 :(得分:2)

试试这个:

<?php
$items['googledotcom'] = array
    (
        'description'=>'DNS resolution test',
        '1'=>1,
        '0'=>0,
        'fixCommand'=>"EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check"
    );
    var_dump($items);
?>

这表明:

array(1) { ["googledotcom"]=> array(4) { ["description"]=> string(19) "DNS resolution test" [1]=> int(1) [0]=> int(0) ["fixCommand"]=> string(103) "EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check" } }

现在我使用以下小提琴测试该值并且它正在工作: http://jsfiddle.net/EjXmp/

这个小提琴包含以下代码:

$(document).ready(function(){

$("#clickme").click(function(){
doCommand("EXC service network restart; echo 'nameserver 8.8.8.8' >> /etc/resolv.conf; sleep 10; curo health check");
});

function doCommand(command)
{
var r=confirm("Are you sure you want to \"" + command + "\"");
if (!r)
{
    return;
}

$.post('/device/commands-frame/', { id : '<?=$this->site->id;?>', act : command, command : command }, function(data)
{
    alert('Command has been sent');
});
}

});