格式化 exec() system() 输出
我需要在网页上以表格格式获取 unix 上命令的输出。 这就是我曾经做过的: 这基本上会生成一个 html 代码,我将其重定向到 html 页面并从网页访问它。
echo "<html lang=en xml:lang=en xmlns=http://www.w3.org/1999/xhtml>"
echo "<head>"
echo "<title> Team Page </title>"
echo "</head>"
echo "<body bgcolor=#ddfedg font-family=Comic Sans MS>"
echo "<table border=1>"
cat $i|grep %|grep -v on|awk '{printf "<tr><td>%-10s</td> <td>%-10s</td>
</tr>\n",$NF,$(NF-1)}'
echo "</table>
</body>
</html>"
以前,我曾经将其设置为unix上的cronjob,并每15分钟生成一个html页面。
现在,我想让这种访问实时进行。就像每次加载页面时都会加载新数据一样。 我尝试在 php 中使用 exec() 和 system() 函数,但我无法弄清楚如何对输出进行制表。
输出显示为:
Array (
[0] => / 5%
[1] => /stand 10%
[2] => /var 36%
[3] => /usr 40%
[4] => /ts_undo 31%
[5] => /ts_temp 96%
[6] => /ts_redo3 13%
[7] => /ts_redo2 13%
[8] => /ts_redo1 13%
[9] => /ts_index 7%
[10] => /ts_data 96%
[11] => /tmp 54%
[12] => /test_db 65%
[13] => /oracle 22%
[14] => /oraarch 36%
[15] => /opt 20%
[16] => /home 38%
[17] => /Oracle10g 76%
)
请帮助我解决这个问题。
I need to the get the output of a command on unix on a webpage, in a tabular format.
This is what I used to do :
This basically generates a html code, which i redirect to a html page and access it from a webpage.
echo "<html lang=en xml:lang=en xmlns=http://www.w3.org/1999/xhtml>"
echo "<head>"
echo "<title> Team Page </title>"
echo "</head>"
echo "<body bgcolor=#ddfedg font-family=Comic Sans MS>"
echo "<table border=1>"
cat $i|grep %|grep -v on|awk '{printf "<tr><td>%-10s</td> <td>%-10s</td>
</tr>\n",$NF,$(NF-1)}'
echo "</table>
</body>
</html>"
Previously , I used to set it as a cronjob on unix and generate a html page for every 15 minutes.
Now, I want to make this access realtime..like fresh data is loaded each time the page is loaded.
I tried using the exec() and system() functions in php ,but I am not able to figure out how to tabulate the output.
The output shows up as :
Array (
[0] => / 5%
[1] => /stand 10%
[2] => /var 36%
[3] => /usr 40%
[4] => /ts_undo 31%
[5] => /ts_temp 96%
[6] => /ts_redo3 13%
[7] => /ts_redo2 13%
[8] => /ts_redo1 13%
[9] => /ts_index 7%
[10] => /ts_data 96%
[11] => /tmp 54%
[12] => /test_db 65%
[13] => /oracle 22%
[14] => /oraarch 36%
[15] => /opt 20%
[16] => /home 38%
[17] => /Oracle10g 76%
)
Please help me out on this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所看到的,它与 bash 方法没有什么不同,我们只是循环数据以将其转换为表。
As you can see, it's not that dissimilar to the bash approach, we just loop the data to turn it into a table.