antony@notes:~/container$ cat "在Alpine-Linux架站.md"
在Alpine Linux架站
在Alpine Linux架站
下載一般的server版可以跑的busybox,像是Ubuntu server或是Centos server版
alp:~$ wget https://busybox.net/downloads/binaries/1.28.1-defconfig-multiarch/busybox-x86_64
而alpine linux是sudo apk add busybox-extras
alp:~$ sudo apk add busybox-extras
(1/1) Installing busybox-extras (1.34.1-r4)
Executing busybox-extras-1.34.1-r4.post-install
Executing busybox-1.34.1-r4.trigger
OK: 77 MiB in 97 packages先建立一個目錄
mkdir webroot
寫入網站內容
alp:~$ echo '<html><head>Welcome to Alpine Linux</head><body><p>Hello</p></body></html>' >index.html
p 是文字標籤 網頁文字樣式查詢
把寫好的內容丟到剛剛的目錄
alp:~$ mv index.html ./webroot/
把busybox網站服務啟動
alp:~$ sudo busybox-extras httpd -p 80 -h ./webroot/
-p 預設是80 port -h 是
下載新的網頁
alp:~$ wget https://www.free-css.com/assets/files/free-css-templates/download/page275/edulab.zip
解壓縮edulab.zip
alp:~$ unzip edulab.zip確定有無index.html,打到/edulab/in按tab鍵看有沒有自動補上
alp:~$ ls -al /edulab/index.html
刪掉壓縮檔
alp:~$ rm edulab.zip
把edulab名字改成myweb
alp:~$ mv edulab myweb
啟動網站
alp:~$ sudo busybox-extras httpd -p 8080 -h myweb/
如何刪除網站 alp:~$ ps aux
root 3554 0.0 0.0 876 40 ? Ss 09:31 0:00 busybox-extras httpd -p 80 -h ./webroot/
root 3717 0.1 0.0 0 0 ? I 09:58 0:02 [kworker/u256:2-events_unbound]
root 3739 0.0 0.0 0 0 ? R 10:02 0:01 [kworker/u256:3+events_unbound]
root 3838 0.0 0.0 876 392 ? Ss 10:19 0:00 busybox-extras httpd -p 8080 -h myweb/
root 3891 0.0 0.0 0 0 ? R 10:20 0:00 [kworker/u256:0-events_unbound]
root 3936 0.0 0.0 1584 4 ttyS0 Ss+ 10:28 0:00 /sbin/getty -L 0 ttyS0 vt100
bigred 3938 0.0 0.1 1708 884 pts/0 R+ 10:28 0:00 ps aux找到我們開啟的 myweb
root 3838 0.0 0.0 876 392 ? Ss 10:19 0:00 busybox-extras httpd -p 8080 -h myweb/刪除他的pid
sudo kill -9 3838
看哪個port號沒被應用程式佔用 http://www.penguintutor.com/linux/services-tcp-udp-port-numbers-quickreference
編輯網頁內容
<html>
<head>Welcome to Alpine Linux</head>
<body>
<p style="color:red; ">Hello</p>
<div style="background-color:tomato; text-align:center; ">A red paragraph </div>
</body>
</html>
如果改完網站內容,發現網站沒有更新
到 “設定” »> “安全性與隱私權” »> “清除歷史資料”

按清除資料

最後再重新整理網站
下載口罩資料
先建立一個目錄
alp:~$ mkdir raw
到政府開放平台下載資料,在csv那裡按右鍵,選複製連結網址

下載資料,用-O參數把名字改成mask.csv,網址前後加單引號
alp:~$ wget 'https://quality.data.gov.tw/dq_download_csv.php?nid=116285&md5_url=53a72b2dcfdd9ecae43afda4b86089be' -O mask.csv--2022-03-30 13:10:27-- https://quality.data.gov.tw/dq_download_csv.php?nid=116285&md5_url=53a72b2dcfdd9ecae43afda4b86089be
Resolving quality.data.gov.tw (quality.data.gov.tw)... 223.200.181.141
Connecting to quality.data.gov.tw (quality.data.gov.tw)|223.200.181.141|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/csv]
Saving to: 'mask.csv'
mask.csv [ <=> ] 540.55K --.-KB/s in 0.03s
2022-03-30 13:10:27 (15.9 MB/s) - 'mask.csv' saved [553522]確認資料是否正確
alp:~$ cat raw/mask.csv | head -n 5
醫事機構代碼,醫事機構名稱,醫事機構地址,醫事機構電話,成人口罩剩餘數,兒童口罩剩餘數,來源資料時間
0145080011,衛生福利部花蓮醫院豐濱原住民分院,花蓮縣豐濱鄉豐濱村光豐路41號,8358141,1770,1720,2021/06/30 14:32:25
0291010010,連江縣立醫院,連江縣南竿鄉復興村217號,623995,8000,1150,2021/06/30 14:32:25
2312010014,新竹市東區衛生所,新竹市東區民族路40之2號,(03)5236158,4230,1260,2021/06/30 14:32:25
2312041028,新竹市北區衛生所,新竹市北區國華街六十九號一樓,(03)5353969,800,1370,2021/06/30 14:32:25把mask.csv移到raw目錄下
alp:~$ mv mask.csv raw/
把第一行去掉,並輸出到./raw/mask0330.csv
alp:~$ cat raw/mask.csv | tail -n +2 >./raw/mask0330.csv
檢查剛剛的動作有無錯誤
alp:~$ ls -l raw
total 1088
-rw-r--r-- 1 bigred bigred 553522 Mar 30 13:10 mask.csv
-rw-r--r-- 1 bigred bigred 553383 Mar 30 13:16 mask0330.csv收尋開頭是0的資料
alp:~$ cat ./raw/mask0330.csv | grep "^0"
0145080011,衛生福利部花蓮醫院豐濱原住民分院,花蓮縣豐濱鄉豐濱村光豐路41號,8358141,1770,1720,2021/06/30 14:32:25
0291010010,連江縣立醫院,連江縣南竿鄉復興村217號,623995,8000,1150,2021/06/30 14:32:25把藥局(5) 醫院(0) 衛生所(2)分別輸出到h.txt c.txt m.txt
alp:~$ cat ./raw/mask0330.csv | grep "^0" >h.txt
alp:~$ cat ./raw/mask0330.csv | grep "^2" >c.txt
alp:~$ cat ./raw/mask0330.csv | grep "^5" >m.txt
alp:~$ ls -l
total 564
drwxr-sr-x 2 bigred bigred 4096 Mar 30 09:15 bin
-rw-r--r-- 1 bigred bigred 17606 Mar 30 13:32 c.txt
-rw-r--r-- 1 bigred bigred 251 Mar 30 13:32 h.txt
-rw-r--r-- 1 bigred bigred 535526 Mar 30 13:33 m.txt
drwxr-sr-x 6 bigred bigred 4096 Mar 30 09:43 myweb
drwxr-sr-x 2 bigred bigred 4096 Mar 30 13:16 raw
drwxr-sr-x 2 bigred bigred 4096 Mar 30 09:24 webroot練習1:寫程式算一下,今日全省健康中心剩於的成人口罩數量是多少
練習2:金門縣兒童口罩及成人口罩剩餘
300 cat raw/mask0330.csv | grep '金門縣' | cut -d ',' -f5 >sum_a.csv
301 cat raw/mask0330.csv | grep '金門縣' | cut -d ',' -f6 >sum_k.csv
302 ls
305 cp test1/sum.sh sum3.sh
306 nano sum3.sh
#!/bin/bash
s=0
while read -r line
do
s=$((s+$line))
done < sum_a.csv
echo "Aldult mask,$s" >>result2.txt
307 ./sum3.sh
308 cat result2.txt
309 cp sum3.sh sum4.sh
310 nano sum4.sh
#!/bin/bash
s=0
while read -r line
do
s=$((s+$line))
done < sum_k.csv
echo "Kid mask,$s" >>result2.txt
311 ./sum4.sh
312 cat result2.txt
313 clear
314 ls -l webroot/
315 ls -l webroot/result.files/
316 mv webroot/result.files/result.htm webroot/
317 ls -l webroot/
318 tree webroot/