<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UI 網站 &#187; shell</title>
	<atom:link href="http://ui.idv.tw/wordpress/?feed=rss2&#038;tag=shell" rel="self" type="application/rss+xml" />
	<link>https://ui.idv.tw/wordpress</link>
	<description>個人雜亂筆記用</description>
	<lastBuildDate>Wed, 15 Oct 2025 10:08:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>linux shell &#8211; 陣列帶入</title>
		<link>https://ui.idv.tw/wordpress/?p=1106</link>
		<comments>https://ui.idv.tw/wordpress/?p=1106#comments</comments>
		<pubDate>Sun, 15 Jan 2023 13:57:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[未分類]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ui.idv.tw/wordpress/?p=1106</guid>
		<description><![CDATA[使用 $() 或 " 結果帶入陣列 例:var1=($(df / &#124; tail -n +2)) 關聯數組 delclare -A var1 man=([name]=jessic [age]=25 [addr]=taipei) 列出陣列全部內容 echo ${man[*]} 刪除內容 unset ${man[age]} 刪除陣列 user man]]></description>
			<content:encoded><![CDATA[<p>使用 $() 或 " 結果帶入陣列<br />
例:var1=($(df / | tail -n +2))</p>
<p>關聯數組<br />
delclare -A var1<br />
man=([name]=jessic [age]=25 [addr]=taipei)</p>
<p>列出陣列全部內容<br />
echo ${man[*]}</p>
<p>刪除內容<br />
unset ${man[age]}</p>
<p>刪除陣列<br />
user man</p>
]]></content:encoded>
			<wfw:commentRss>https://ui.idv.tw/wordpress/?feed=rss2&#038;p=1106</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shc 編譯</title>
		<link>https://ui.idv.tw/wordpress/?p=913</link>
		<comments>https://ui.idv.tw/wordpress/?p=913#comments</comments>
		<pubDate>Sat, 28 May 2022 15:35:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ui.idv.tw/wordpress/?p=913</guid>
		<description><![CDATA[來源: https://github.com/neurobin/shc/releases 1. wget https://github.com/neurobin/shc/archive/refs/tags/4.0.3.tar.gz 2. tar -zxvf 4.0.3.tar.gz 3. ./configure;make;make install 4. 編輯自己的 shell script shc -r -v -f 編譯過後為 mysscipt.sh.x 針對 script 設可執行期限 shc -e -m "" -r -f]]></description>
			<content:encoded><![CDATA[<p>來源: https://github.com/neurobin/shc/releases<br />
1.<br />
wget https://github.com/neurobin/shc/archive/refs/tags/4.0.3.tar.gz</p>
<p>2.<br />
tar -zxvf 4.0.3.tar.gz</p>
<p>3.<br />
 ./configure;make;make install</p>
<p>4.<br />
編輯自己的 shell script<br />
shc -r -v -f <script name><br />
編譯過後為 mysscipt.sh.x</p>
<p>針對 script 設可執行期限<br />
shc -e
<dd/mm/yyy> -m "<message>" -r -f <script name></p>
]]></content:encoded>
			<wfw:commentRss>https://ui.idv.tw/wordpress/?feed=rss2&#038;p=913</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell 批量 修改檔名</title>
		<link>https://ui.idv.tw/wordpress/?p=476</link>
		<comments>https://ui.idv.tw/wordpress/?p=476#comments</comments>
		<pubDate>Wed, 11 Nov 2020 05:42:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ui.idv.tw/wordpress/?p=476</guid>
		<description><![CDATA[awk + xorg ➜ touch file{0..10}.txt ➜ ls file0.txt file10.txt file1.txt file2.txt file3.txt file4.txt file5.txt file6.txt file7.txt file8.txt file9.txt ➜ ls &#124; awk &#8216;{print $NF}&#8217; &#124; xargs -I {} mv {} update_{} ➜ ls update_file0.txt update_file1.txt update_file3.txt update_file5.txt update_file7.txt update_file9.txt &#8230; <a href="https://ui.idv.tw/wordpress/?p=476">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>awk + xorg</p>
<p>➜ touch file{0..10}.txt<br />
➜ ls<br />
file0.txt  file10.txt  file1.txt  file2.txt  file3.txt  file4.txt  file5.txt  file6.txt  file7.txt  file8.txt  file9.txt<br />
➜  ls | awk &#8216;{print $NF}&#8217; | xargs -I {} mv {} update_{}<br />
➜  ls<br />
update_file0.txt   update_file1.txt  update_file3.txt  update_file5.txt  update_file7.txt  update_file9.txt<br />
update_file10.txt  update_file2.txt  update_file4.txt  update_file6.txt  update_file8.txt</p>
<p>bash<br />
➜   touch file{1..10}.txt<br />
➜   ls<br />
file10.txt  file1.txt  file2.txt  file3.txt  file4.txt  file5.txt  file6.txt  file7.txt  file8.txt  file9.txt<br />
➜   num=0; for i in *; do mv "$i" "$(printf &#8216;%04d&#8217; $num).${i#*.}"; ((num++)); done<br />
➜   ls<br />
0000.txt  0001.txt  0002.txt  0003.txt  0004.txt  0005.txt  0006.txt  0007.txt  0008.txt  0009.txt</p>
]]></content:encoded>
			<wfw:commentRss>https://ui.idv.tw/wordpress/?feed=rss2&#038;p=476</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Script 監測硬碟使用量</title>
		<link>https://ui.idv.tw/wordpress/?p=392</link>
		<comments>https://ui.idv.tw/wordpress/?p=392#comments</comments>
		<pubDate>Tue, 11 Jul 2017 08:19:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ui.idv.tw/wordpress/?p=392</guid>
		<description><![CDATA[https://www.phpini.com/linux/shell-script-check-harddisk-usage Shell Script 監測硬碟使用量 #!/bin/bash toemail="you@youremail.com" alert=90 df -H &#124; grep -vE &#8216;^Filesystem&#124;tmpfs&#8217; &#124; awk &#8216;{ print $5 " " $6 }&#8217; &#124; while read output; do usepercent=$(echo $output &#124; awk &#8216;{ print $1}&#8217; &#124; cut -d&#8217;%&#8217; -f1 ) partition=$(echo &#8230; <a href="https://ui.idv.tw/wordpress/?p=392">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>https://www.phpini.com/linux/shell-script-check-harddisk-usage</p>
<p>Shell Script 監測硬碟使用量<br />
#!/bin/bash</p>
<p>toemail="you@youremail.com"<br />
alert=90</p>
<p>df -H | grep -vE &#8216;^Filesystem|tmpfs&#8217; | awk &#8216;{ print $5 " " $6 }&#8217; | while read output;<br />
do<br />
        usepercent=$(echo $output | awk &#8216;{ print $1}&#8217; | cut -d&#8217;%&#8217; -f1  )<br />
        partition=$(echo $output | awk &#8216;{ print $2 }&#8217; )<br />
        if [ $usepercent -ge $alert ]; then<br />
                echo "$(date): $(hostname) Disk Space Alert: \"$partition ($usepercent%)\"" |<br />
                mail -s "$(hostname) Disk Space Alert" $toemail<br />
        fi<br />
done</p>
<p>0 0 * * * /path/to/check-disk.sh > /dev/null 2>&#038;1</p>
]]></content:encoded>
			<wfw:commentRss>https://ui.idv.tw/wordpress/?feed=rss2&#038;p=392</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>目的：將多個網域資料，利用script轉入DNS的設定中，減少手動輸入的機會</title>
		<link>https://ui.idv.tw/wordpress/?p=232</link>
		<comments>https://ui.idv.tw/wordpress/?p=232#comments</comments>
		<pubDate>Tue, 28 May 2013 11:26:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[未分類]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ui.idv.tw/wordpress/?p=232</guid>
		<description><![CDATA[目的：將多個網域資料，利用script轉入DNS的設定中，減少手動輸入的機會 想法：將欲將入的網域名稱建list為newlist檔，經判別分離可能的主機與網域名稱導為tmp檔 再傳入函式判別是否已存在於記錄中，分別處理 結果：可成功自動轉入，看無法檢查大小寫之差異，等於半自動，但，已減少很多工作了 注意：script shell中最好不要函中文註解 basezone zone "antizone" { type master; file "/var/named/gsnanti/data/antizone.host"; allow-update {none; }; }; basehost $ttl 38400 antizone. IN SOA dns.khb.gov.tw. root.dns.khb.gov.tw. ( 1284022127 10800 3600 604800 38400 ) antizone. IN NS dns.khb.gov.tw. fullzone. IN A &#8230; <a href="https://ui.idv.tw/wordpress/?p=232">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>目的：將多個網域資料，利用script轉入DNS的設定中，減少手動輸入的機會</p>
<p>想法：將欲將入的網域名稱建list為newlist檔，經判別分離可能的主機與網域名稱導為tmp檔</p>
<p>        再傳入函式判別是否已存在於記錄中，分別處理</p>
<p>結果：可成功自動轉入，看無法檢查大小寫之差異，等於半自動，但，已減少很多工作了</p>
<p>注意：script shell中最好不要函中文註解</p>
<p>basezone</p>
<p>zone "antizone" {<br />
        type master;<br />
        file "/var/named/gsnanti/data/antizone.host";<br />
        allow-update {none; };<br />
        };</p>
<p>basehost</p>
<p>$ttl 38400<br />
antizone.       IN      SOA     dns.khb.gov.tw. root.dns.khb.gov.tw. (<br />
                        1284022127<br />
                        10800<br />
                        3600<br />
                        604800<br />
                        38400 )<br />
antizone.       IN      NS      dns.khb.gov.tw.<br />
fullzone.  IN      A       1.1.1.100</p>
<p>anti.zones</p>
<p># GSN anti DS<br />
zone "m-music.net" {<br />
        type master;<br />
        file "/var/named/gsnanti/data/m-music.net.host";<br />
        allow-update {none; };<br />
        };</p>
<p>gsn</p>
<p>#!/bin/bash<br />
//宣告函式</p>
<p>//基本設定檔basezone及basehost與anti.zones</p>
<p>//導入二個參數<br />
function append_data()<br />
{<br />
        var1=$1<br />
        var2=$2<br />
if grep $var1 anti.zones > /dev/null;    //檢驗參數值是否已存在，並將比對的結果回應值導至null<br />
then<br />
        echo "Domain $var1 exists"<br />
        echo "$var2.    IN      A       1.1.1.100&#8243; >> data/$var1.host<br />
else<br />
        sed -e &#8216;s/antizone/&#8217;"$var1&#8243;&#8216;/g&#8217; basezone >> anti.zones<br />
        sed -e &#8216;s/antizone/&#8217;"$var1&#8243;&#8216;/g&#8217; basehost | sed &#8216;s/fullzone/&#8217;"$var2&#8243;&#8216;/g&#8217; >  data/$var1.host<br />
fi<br />
}<br />
//下列主要目的是將newlist中所含網域名稱，利用awk分解為List，再轉入tmp檔<br />
cat newlist | awk &#8216;BEGIN {FS="."}{if (NF==2) printf $0&#8243;,"$0&#8243;\n"}<br />
        {if (NF==3) printf $(NF-1)"."$NF","$0&#8243;\n"}<br />
        {if (NF>=4) printf $(NF-2)"."$(NF-1)"."$NF","$0&#8243;\n"}&#8217; >> tmp</p>
<p>//以cut將tmp內主機及網域資料導入矩陣中，再將矩陣傳入函式中</p>
<p>sel_1=($(cut -d "," -f1 tmp))<br />
sel_2=($(cut -d "," -f2 tmp))<br />
se1=${#sel_1[@]}        // 取矩陣大小<br />
for ((i=0;i<=$se1-1;i=i+1))<br />
do<br />
append_data "${sel_1[$i]}" "${sel_2[$i]}"<br />
done</p>
]]></content:encoded>
			<wfw:commentRss>https://ui.idv.tw/wordpress/?feed=rss2&#038;p=232</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
