Jump to content

exec() using bash instead of sh?


OneSeventeen

Recommended Posts

I would like PHP to kick off the following command:

arp -a|sed 's/ /,/g'>arp.csv

 

I also have an executable makeArpFile.sh:

#!/bin/bash
arp -a|sed 's/ /,/g'>arp.csv

 

And I have tried executing it in php with the following:

$arp = exec("bash makeArpFile.sh", $output, $exit_code);
echo("Last line: " . $arp . "\n");
echo("Output: " . $output . "\n");
echo("Exit Code: " . $exit_code . "\n");
/*returns:
Last line: 
Output: 
Exit Code: 127
*/

 

I also tried just plain old:

$arp = exec("makeArpFile.sh", $output, $exit_code);
echo("Last line: " . $arp . "\n");
echo("Output: " . $output . "\n");
echo("Exit Code: " . $exit_code . "\n");
/*returns:
Last line: 
Output: 
Exit Code: 127
*/

 

I can run plain old arp>arp.txt but I really need it formatted in BSD style (arp -a>arp.txt) in order to be able to parse it properly later.

 

Any thoughts?

 

EDIT:

for fun I made a useBash.sh script that executed "bash makeArpFile.sh" still no luck.

Link to comment
https://forums.phpfreaks.com/topic/217850-exec-using-bash-instead-of-sh/
Share on other sites

Yes, makeArpFile.sh is executable.

 

I'm a moron though, and created the arp.csv file with the same filename as the command I'm trying to execute (arp)

 

when I give the full path to arp, it works beautifully:

$arp = exec("/usr/sbin/arp -a|sed 's/ /,/g'>arp.csv", $output, $exit_code);

 

Thanks for the point in the right direction!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.