Skip to content

Commit d973dd1

Browse files
author
Toyo
authored
# v1.0.2 一些小细节完善
1 parent b63f535 commit d973dd1

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

pythonhttp.sh

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
33
export PATH
44

55
#=================================================
6-
# System Required: All
7-
# Description: Python HTTP Server
8-
# Author: Toyo
9-
# Blog: https://doub.io/wlzy-8/
6+
# System Required: All
7+
# Description: Python HTTP Server
8+
# Version: 1.0.2
9+
# Author: Toyo
10+
# Blog: https://doub.io/wlzy-8/
1011
#=================================================
1112

1213
sethttp(){
@@ -15,10 +16,10 @@ sethttp(){
1516
do
1617
echo -e "请输入要开放的HTTP服务端口 [1-65535]"
1718
stty erase '^H' && read -p "(默认端口: 8000):" httpport
18-
[ -z "$httpport" ] && httpport="8000"
19+
[[ -z "$httpport" ]] && httpport="8000"
1920
expr ${httpport} + 0 &>/dev/null
20-
if [ $? -eq 0 ]; then
21-
if [ ${httpport} -ge 1 ] && [ ${httpport} -le 65535 ]; then
21+
if [[ $? -eq 0 ]]; then
22+
if [[ ${httpport} -ge 1 ]] && [[ ${httpport} -le 65535 ]]; then
2223
echo
2324
echo -e " 端口 : \033[41;37m ${httpport} \033[0m"
2425
echo
@@ -33,8 +34,8 @@ sethttp(){
3334
#设置目录
3435
echo "请输入要开放的目录(绝对路径)"
3536
stty erase '^H' && read -p "(直接回车, 默认当前文件夹):" httpfile
36-
if [ ! -z $httpfile ]; then
37-
[ ! -e $httpfile ] && echo -e "\033[41;37m [错误] \033[0m 输入的目录不存在 或 当前用户无权限访问, 请检查!" && exit 1
37+
if [[ ! -z $httpfile ]]; then
38+
[[ ! -e $httpfile ]] && echo -e "\033[41;37m [错误] \033[0m 输入的目录不存在 或 当前用户无权限访问, 请检查!" && exit 1
3839
else
3940
httpfile=`echo $PWD`
4041
fi
@@ -59,18 +60,18 @@ iptables_del(){
5960
}
6061
starthttp(){
6162
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
62-
[ ! -z $PID ] && echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 正着运行,请检查 !" && exit 1
63+
[[ ! -z $PID ]] && echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 正着运行,请检查 !" && exit 1
6364
sethttp
6465
iptables_add
6566
cd ${httpfile}
6667
nohup python -m SimpleHTTPServer $httpport >> httpserver.log 2>&1 &
6768
sleep 2s
6869
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
69-
if [ -z $PID ]; then
70+
if [[ -z $PID ]]; then
7071
echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 启动失败 !" && exit 1
7172
else
7273
ip=`curl -m 10 -s http://members.3322.org/dyndns/getip`
73-
[ -z "$ip" ] && ip="VPS_IP"
74+
[[ -z "$ip" ]] && ip="VPS_IP"
7475
echo
7576
echo "HTTP服务 已启动 !"
7677
echo -e "浏览器访问,地址: \033[41;37m http://${ip}:${httpport} \033[0m "
@@ -79,13 +80,13 @@ starthttp(){
7980
}
8081
stophttp(){
8182
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
82-
[ -z $PID ] && echo -e "\033[41;37m [错误] \033[0m 没有发现 SimpleHTTPServer 进程运行,请检查 !" && exit 1
83+
[[ -z $PID ]] && echo -e "\033[41;37m [错误] \033[0m 没有发现 SimpleHTTPServer 进程运行,请检查 !" && exit 1
8384
port=`netstat -lntp | grep ${PID} | awk '{print $4}' | awk -F ":" '{print $2}'`
8485
iptables_del
8586
kill -9 ${PID}
8687
sleep 2s
8788
PID=`ps -ef | grep SimpleHTTPServer | grep -v grep | awk '{print $2}'`
88-
if [ ! -z $PID ]; then
89+
if [[ ! -z $PID ]]; then
8990
echo -e "\033[41;37m [错误] \033[0m SimpleHTTPServer 停止失败 !" && exit 1
9091
else
9192
echo
@@ -95,7 +96,7 @@ stophttp(){
9596
}
9697

9798
action=$1
98-
[ -z $1 ] && action=start
99+
[[ -z $1 ]] && action=start
99100
case "$action" in
100101
start|stop)
101102
${action}http

0 commit comments

Comments
 (0)