This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
средства_программирования_shell [2022/06/06 10:13] val [CGI на shell] |
средства_программирования_shell [2022/09/22 11:47] val [Ресурсы Web сервера на shell] |
||
---|---|---|---|
Line 4: | Line 4: | ||
* [[http://mywiki.wooledge.org/BashFAQ|Часто задаваемые вопросы про bash (eng)]] | * [[http://mywiki.wooledge.org/BashFAQ|Часто задаваемые вопросы про bash (eng)]] | ||
* [[https://habrahabr.ru/post/335960/|Играючи BASH'им]] | * [[https://habrahabr.ru/post/335960/|Играючи BASH'им]] | ||
+ | |||
* [[https://youtu.be/GxVmukxVUo0|Видео урок]] | * [[https://youtu.be/GxVmukxVUo0|Видео урок]] | ||
+ | |||
* [[https://www.tutorialspoint.com/execute_bash_online.php|Execute Bash Shell Online]] | * [[https://www.tutorialspoint.com/execute_bash_online.php|Execute Bash Shell Online]] | ||
+ | * [[https://www.shellcheck.net/|ShellCheck finds bugs in your shell scripts.]] | ||
===== Проверка синтаксиса ===== | ===== Проверка синтаксиса ===== | ||
Line 11: | Line 14: | ||
# apt install shellcheck | # apt install shellcheck | ||
- | $ shellcheck script.sh | + | $ shellcheck webd/webd |
</code> | </code> | ||
===== Переменные окружения ===== | ===== Переменные окружения ===== | ||
Line 369: | Line 372: | ||
* [[http://underpop.online.fr/c/cgi/docs/creating-cgi-programs-with-bash/|Creating CGI Programs with Bash: Introduction]] | * [[http://underpop.online.fr/c/cgi/docs/creating-cgi-programs-with-bash/|Creating CGI Programs with Bash: Introduction]] | ||
+ | * [[https://debian-administration.org/article/371/A_web_server_in_a_shell_script|A web server in a shell script]] | ||
* [[https://stackoverflow.com/questions/16640054/minimal-web-server-using-netcat|Minimal web server using netcat]] | * [[https://stackoverflow.com/questions/16640054/minimal-web-server-using-netcat|Minimal web server using netcat]] | ||
+ | * [[https://funprojects.blog/2021/04/11/a-web-server-in-1-line-of-bash/|A Web Server in 1 Line of Bash Code]] | ||
==== Web сервер на shell ==== | ==== Web сервер на shell ==== | ||
- | * [[https://debian-administration.org/article/371/A_web_server_in_a_shell_script|A web server in a shell script]] | + | * [[Сервис HTTP]] |
<code> | <code> | ||
Line 380: | Line 385: | ||
#!/bin/bash | #!/bin/bash | ||
base=/var/www | base=/var/www | ||
+ | log=/var/log/webd.log | ||
read request | read request | ||
Line 385: | Line 391: | ||
while : | while : | ||
do | do | ||
- | read header | + | read -r header |
[ "$header" == $'\r' ] && break; | [ "$header" == $'\r' ] && break; | ||
done | done | ||
Line 398: | Line 404: | ||
if [ -e "$filename" ] | if [ -e "$filename" ] | ||
then | then | ||
+ | echo `date` OK $url >> $log | ||
echo -e "HTTP/1.1 200 OK\r" | echo -e "HTTP/1.1 200 OK\r" | ||
- | echo -e "Content-Type: `/usr/bin/file -bi \"$filename\"`\r" | + | echo -e "Content-Type: $(/usr/bin/file -bi \"$filename\")\r" |
echo -e "\r" | echo -e "\r" | ||
/bin/cat "$filename" | /bin/cat "$filename" | ||
else | else | ||
+ | echo "$(date)" ERR $url >> $log | ||
echo -e "HTTP/1.1 404 Not Found\r" | echo -e "HTTP/1.1 404 Not Found\r" | ||
echo -e "Content-Type: text/html;\r" | echo -e "Content-Type: text/html;\r" | ||
echo -e "\r" | echo -e "\r" | ||
- | echo -e "<h1>Not Found</h1>" | + | ip=$(cat /proc/net/fib_trie | awk '/32 host/ { print f } {f=$2}' | sort -u | grep -v 127.0.0.1) |
+ | echo -e "<h1>$url Not Found in container $(hostname) with ip $ip</h1>" | ||
+ | echo "ver 1.1" | ||
fi | fi | ||
- | |||
</code> | </code> | ||
Line 433: | Line 442: | ||
</code> | </code> | ||
+ | * [[Сервис INETD]] | ||
==== Проверка ==== | ==== Проверка ==== | ||