Execution of command in linux from php

3

I have the following command that I want to execute in the shell of Linux since php but it does not work for me, I used exec , php_exec system . but nothing.

'iw dev $target station dump | grep Station | cut -f 2 -s -d' ''

I receive as parameter target from php and it shows me an error as if the parameters arrived incorrectly I check and it is ok, and changing the variable target by the card directly works, I do not know if someone can help me . I use php7 and deepinOS .

this is the function php7.0

function list_connect($interface){

 $names = file($interface);


     foreach($names as $name)
     {
         $target = $names[0];
         $broadcast = $names[1];
     }

    $query = "iw dev $target station dump | grep Station | cut -f 2 -s -d' '";
    $maclist = shell_exec($query);

    var_dump($maclist);

    }   

    list_connect($path_logs_condor_TARGET_LIST);'
    
asked by Samir Sanchez Garnica 19.12.2016 в 18:03
source

1 answer

1

I tried and it works:

<?php
    $query = "iw dev wlan0 station dump | grep Station | cut -f 2 -s -d' '";
    $maclist = shell_exec($query);
    var_dump($maclist);

Exit:

string(18) "xx:xx:db:xx:58:d0 "

What is not clear to me is that you use your for each, if you are going to run your shell_exec out of it. Either you pass it directly to the interface, or inside a foreach you put the shell_exec

Likewise, I think that the interface is not working well, that's why it does not work for you. To verify the value of $ target do a var_dump before running the shell_exec.

Surely you're not having a good time with the interface.

    
answered by 20.12.2016 в 01:39