I am totally new to PHP and I am trying to create a script that will as a user for a hostname and then use the "hostname" variable to generate a report using REST API.
I am able to create the html script and php script to GET the "hostname" but I am having trouble passing the hostname variable to the bash script which generates the report using REST API.
Hostname to Query is <?php echo $_GET["hostname"];
$hostname = $argv[1];
#echo "This is $hostname\n";
#$result = shell_exec('/var/www/html/scripts/REST-API/dpa_reports.sh ' . $hostname);
$result = shell_exec('/var/www/html/scripts/REST-API/dpa_reports.sh ' . $hostname);
echo $result;
?><br>
---------- Post updated at 12:38 PM ---------- Previous update was at 12:33 PM ----------
if I do the following from the command line it passes the "hostname" variable to the bash script dpa_report.h script fine. But when I submit the "hostname" from my browser it does not pass the variable...
Assuming that you are using Apache as the web server, you can do the following:
Start an additional terminal window, and run "tail -f /var/log/apache2/error.log". You will get al running list of errors from your web development.
Thank jgt That fixed that particular problem. Now I am getting a curl error though. If I run the curl from the command line I have no issue but when it is called from the php script which calls the bash script I get this error
curl: (7) Failed to connect to 172.16.120.152: Permission denied
The curl command works fine when I do it from the command line.
Any idea why this is happening?
---------- Post updated at 03:36 PM ---------- Previous update was at 03:34 PM ----------
This is the curl command (I have taken out the username and password
This the bash script (dpa_report.sh) that creates the REST -API report. I have taken out the actual username and password for the purposes of this post. If I run this script from the command line and pass it the hostname it works. For example
./dpa_report hostname
works. The hostname is set to $1 in the script.
But when dpa_report.sh is called from the php script I get the permission errors.
This is the error in the apache log when I run curl in verbose. curl -vvv (note: the IP address is correct for seieadpa01)
* About to connect() to seieadpa01 port 9004 (#0)
* Trying 172.16.120.152... Failed to connect to 172.16.120.152: Permission denied
* Success
* couldn't connect to host
* Closing connection #0
When you use curl from your workstation, you are connecting from your workstation. However, when you connect through the web page you are connecting from the web server. The problem may be the two web servers are on different class C networks.
Thanks jgt. I get what you are saying. It definitely has something to do with how my apache webserver communicates with seieadpa01. I will investigate this.
---------- Post updated at 08:02 AM ---------- Previous update was at 07:53 AM ----------
This has been resolved. I ran the following command on my apache server and now I can connect without issues.