html中显示shell脚本的输出,网页从shell脚本中输入并显示结果
首先,不是在BASH腳本中使用$USERNAME。 $USERNAME是一個(gè)包含當(dāng)前用戶(hù)名的BASH變量。實(shí)際上,在BASH中使用UPPERCASE變量通常是一個(gè)糟糕的主意。大多數(shù)BASH環(huán)境變量都是大寫(xiě)字母,可能會(huì)導(dǎo)致混淆。讓你的變量小寫(xiě)是個(gè)好習(xí)慣。
此外,因?yàn)槲蚁肽阆胍褂肏TML表單來(lái)做到這一點(diǎn),所以你不能讓BASH從STDIN中讀取數(shù)據(jù)。修改游腳本以將用戶(hù)名作為參數(shù):
BASH:
#!/bin/bash
user=$1;
DISPLAYNAME=`ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=$user | grep displayName`
if [ -z "$DISPLAYNAME" ]; then
echo "No entry found for $user"
else
echo "Entry found for $user"
fi
的Perl:
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use warnings;
## Create a new CGI object
my $cgi = new CGI;
## Collect the value of 'user_name' submitted by the webpage
my $name=$cgi->param('user_name');
## Run a system command, your display_name.sh,
## and save the result in $result
my $result=`./display_name.sh $name`;
## Print the HTML header
print header;
## Print the result
print "$result
";
HTML:
這應(yīng)該做你所需要的。它假設(shè)這兩個(gè)腳本都位于網(wǎng)頁(yè)的./cgi-bin/目錄中,并被稱(chēng)為display_name.sh和display_name.pl。它還假定你已經(jīng)正確設(shè)置了他們的權(quán)限(他們需要由apache2的用戶(hù)www-data執(zhí)行)。最后,它假定您已經(jīng)設(shè)置了apache2來(lái)允許執(zhí)行./cgi-bin中的腳本。
是否有您想使用BASH的特定原因?您可以直接從Perl腳本執(zhí)行所有操作:
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use warnings;
## Create a new CGI object
my $cgi = new CGI;
## Collect the value of 'name' submitted by the webpage
my $name=$cgi->param('user_name');
## Run the ldapsearch system command
## and save the result in $result
my $result=`ldapsearch -p xxx -LLL -x -w test -h abc.com -D abc -b dc=abc,dc=com sAMAccountName=$name | grep displayName`;
## Print the HTML header
print header;
## Print the result
$result ?
print "Entry found for $name
" :
print "No entry found for $name
";
總結(jié)
以上是生活随笔為你收集整理的html中显示shell脚本的输出,网页从shell脚本中输入并显示结果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 笔记本电脑一碰鼠标就叫(电脑一动鼠标就响
- 下一篇: 我的世界电脑版转化桌(我的世界电脑版转化