日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html中显示shell脚本的输出,网页从shell脚本中输入并显示结果

發布時間:2023/12/3 编程问答 83 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html中显示shell脚本的输出,网页从shell脚本中输入并显示结果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先,不是在BASH腳本中使用$USERNAME。 $USERNAME是一個包含當前用戶名的BASH變量。實際上,在BASH中使用UPPERCASE變量通常是一個糟糕的主意。大多數BASH環境變量都是大寫字母,可能會導致混淆。讓你的變量小寫是個好習慣。

此外,因為我想你想要使用HTML表單來做到這一點,所以你不能讓BASH從STDIN中讀取數據。修改游腳本以將用戶名作為參數:

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:

這應該做你所需要的。它假設這兩個腳本都位于網頁的./cgi-bin/目錄中,并被稱為display_name.sh和display_name.pl。它還假定你已經正確設置了他們的權限(他們需要由apache2的用戶www-data執行)。最后,它假定您已經設置了apache2來允許執行./cgi-bin中的腳本。

是否有您想使用BASH的特定原因?您可以直接從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 '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
";

總結

以上是生活随笔為你收集整理的html中显示shell脚本的输出,网页从shell脚本中输入并显示结果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。