2016-05-10 7 views
2

Ich habe derzeit ein Problem, wo ich versuche, ein Shell-Skript auszuführen, das eine Datei interpretiert und HTML zurückgibt, das Shell-Skript wird perfekt lokal ausgeführt, aber wenn ich über PHP ausführen, tut es nicht alles zurückgeben und es scheint, obwohl PHP es überhaupt nicht ausführt, habe ich eine Datei, die erstellt wird, wenn das Skript ausgeführt wird, die nicht mit PHP-Ausführung angezeigt wird. Ich habe andere Skripte, die mit PHP ausgeführt werden und vollständig funktionieren, und ich habe richtige www-Datenberechtigungen, um diese Datei auszuführen. Bitte helfen Sie mir, hier ist das Skript, das ich ausführen möchte und die PHP-Datei, die es ausführt.PHP + Shell Returning HTML

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>Untitled Document</title> 
 
<link href="style.css" rel="stylesheet" type="text/css"> 
 
</head> 
 
<body> 
 
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0"> 
 
    <tbody> 
 
    <tr> 
 
     <th style="font-size: 24px" scope="col"><p align="left" class="title_Font">Magnum Dongs <span style="font-size: 18px">&nbsp;|&nbsp; Mighty Meat Sticks 4 Kidz</span></p></th> 
 
    </tr> 
 
    </tbody> 
 
</table> 
 
<ul align="center" width="1000" height="50"> 
 
    <li><a href="#home">Home</a></li> 
 
    <li><a href="#news">Stories</a></li> 
 
    <li><a href="#contact">Memes</a></li> 
 
    <li><a href="#about">Shop</a></li> 
 
    <li><a href="#email">Email</a></li> 
 
</ul> 
 
<table width="1000" height="386" border="0" align="center" cellpadding="0" cellspacing="0" class="body_Main"> 
 
    <tbody> 
 
    <?php 
 
    echo exec('./var/www/html/newdongs/fetch_html.sh'); 
 
    ?> 
 
    </tbody> 
 
</table> 
 
</body> 
 
</html>

#!/usr/bin/env bash 
 
python3 /bin/dongs/db_Read.py >> lines 
 
#1 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==11' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==41' lines`"</p>" 
 
echo "<img src='"`awk 'NR==31' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==21' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#2 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==12' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==42' lines`"</p>" 
 
echo "<img src='"`awk 'NR==32' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==22' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#3 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==13' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==43' lines`"</p>" 
 
echo "<img src='"`awk 'NR==33' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==23' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#4 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==14' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==44' lines`"</p>" 
 
echo "<img src='"`awk 'NR==34' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==24' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#5 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==15' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==45' lines`"</p>" 
 
echo "<img src='"`awk 'NR==35' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==25' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#6 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==16' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==46' lines`"</p>" 
 
echo "<img src='"`awk 'NR==36' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==26' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#7 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==17' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==47' lines`"</p>" 
 
echo "<img src='"`awk 'NR==37' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==27' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#8 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==18' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==48' lines`"</p>" 
 
echo "<img src='"`awk 'NR==38' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==28' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#9 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==19' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==49' lines`"</p>" 
 
echo "<img src='"`awk 'NR==39' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==29' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>" 
 
#10 
 
echo "<tr>" 
 
echo "<th scope='col'>" 
 
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" 
 
echo "<tbody>" 
 
echo "<tr>" 
 
echo "<th scope='col' width='50'>" 
 
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==20' lines`"</p>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==50' lines`"</p>" 
 
echo "<img src='"`awk 'NR==40' lines`"' width='150' height='150' alt=''/>" 
 
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" 
 
echo "</th>" 
 
echo "<th scope='col' align='left' valign='top'>" 
 
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==30' lines`"</p>" 
 
echo "</tr>" 
 
echo "</tbody>" 
 
echo "</table></th>"

Danke für die Hilfe im Voraus!

+1

statt exec() versucht, mit system() –

+0

Ich versuchte System() statt, immer noch nichts. Alle Skripte haben chmod 777, also haben sie definitiv Ausführungsrechte. –

+1

Es könnte so viele Dinge geben, die das verursachen. Hast du wenigstens den Pfad überprüft, um sicherzustellen, dass "python3" und "awk" drin sind? Sehen Sie sich das Ergebnis Ihrer Anrufe an, um festzustellen, ob ein Fehler vorliegt? –

Antwort

2

Ich denke, das Problem ist mit PHP suchen das Skript an der falschen Stelle.

Sie können das aktuelle Arbeitsverzeichnis mit getcwd() abrufen. Überprüfen Sie, ob Sie den korrekten relativen Pfad zum Skript in Ihrem aktuellen Arbeitsverzeichnis verwenden.

Andernfalls könnten Sie einfach den absoluten Pfad zum Skript an den exec() Befehl übergeben.

Das nächste Problem ist Ihr Shell-Skript druckt ziemlich viele Zeilen und endet mit den Tags </table></th>. Die Funktion exec() gibt nur die letzte Zeile der Shellskriptausgabe zurück. Die PHP-Ausgabe zeigt also nur die </table></th>. Dies kann nicht in HTML gerendert werden, da es sich nur um die schließenden Tags handelt. Daher sehen Sie keine Änderung im Browser, aber Sie können es bemerken, wenn Sie das HTML überprüfen.

Stattdessen können Sie shell_exec() verwenden, um die gesamte Ausgabe des Shell-Skripts zurückzugeben. Hier

ist die korrigierte Version:

<?php 
// 1.Remove the leading dot. The leading dot makes the path relative. 
// 2.Use shell_exec instead to get all lines from your script output. 
echo shell_exec('/var/www/html/newdongs/fetch_html.sh'); 
?> 
+0

Was meinst du damit, den absoluten Pfad zum Skript an exec() zu übergeben? –

+0

Absoluter Pfad ist der Pfad zum Skript vom Stammordner. Relativer Pfad ist der Pfad zum Skript aus dem aktuellen Arbeitsverzeichnis –

+0

In Ordnung, das ist, was ich dachte, Sie sagten. Ich bekomme immer noch keine Rückkehr von PHP mit Ihren Korrekturen. –