OneSeventeen Posted November 5, 2010 Share Posted November 5, 2010 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 More sharing options...
AbraCadaver Posted November 5, 2010 Share Posted November 5, 2010 1. You probably need to include the full path to makeArpFile.sh 2. Is makeArpFile.sh marked as executable? Link to comment https://forums.phpfreaks.com/topic/217850-exec-using-bash-instead-of-sh/#findComment-1130704 Share on other sites More sharing options...
OneSeventeen Posted November 5, 2010 Author Share Posted November 5, 2010 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! Link to comment https://forums.phpfreaks.com/topic/217850-exec-using-bash-instead-of-sh/#findComment-1130721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.