0

i'm trying to get the value of my vg space disk. When i run the command in my shell i don't have any problem that returns the correct value, but when i include it in a PHP file i have a return of a NULL value.

I have see a lot of threads discuting about it but none of the answers solved my problem :(

What commands works ? This one :

$variable = shell_exec("df -h | grep "username" | awk '{print $3}'");

I don't think it's a permission problem cause this commands works.. For the test script has 777 and root permission.

The code who has the problem :

$test = "VG Size";
$tailletotaleduserveur = shell_exec("vgdisplay vghome | grep ".$test." | awk '{print $3}'");
echo json_encode($tailletotaleduserveur);

The actual result in network tab : null -> http://prntscr.com/nehsmb

It should return "5.85"

Thanks for help :)

2
  • Questions: Which script has mod 777? I don't see a script? What sou you mean with "root permission"? What is the output if df -h? Is there line with literal username? Commented Apr 20, 2019 at 10:07
  • The script which contains the command $tailletotaleduserveur.. The script is owned by root, please read the command who does not works, the df - h is working. You are reading the wrong line. Thanks for help Commented Apr 20, 2019 at 14:52

2 Answers 2

1

Your command fails in a shell as well:

bash$ vgdisplay vghome | grep VG Size | awk '{print $3}'
grep: Size: No such file or directory

You have to quote 'VG Size':

$tailletotaleduserveur = shell_exec("vgdisplay vghome | grep '".$test."' | awk '{print $3}'");
Sign up to request clarification or add additional context in comments.

Comments

0

Final answer for my problem :) :

$test = 'VG Size';
$tailletotaleduserveur = shell_exec("/usr/bin/sudo vgdisplay vghome | grep '".$test."' | awk '{print $3}'");

So that other guy ;) were in part right ;) i will confirm your answer, thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.