差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

linux:shell_script [2022/07/08 17:21]
tony [抓mac]
linux:shell_script [2023/06/25 09:48]
行 1: 行 1:
-{{tag>​Linux ShellScript}} 
-====== Shell Script ====== 
-ShellScript有多強大我不必贅述。我所撰寫的文章都是以前遇到問題所想到的解決方法,也許不是每個做法都很完美,畢竟都是遇到的東西越多,才越能學習到更多更精闢的語法。 
-===== Article List ===== 
-  * [[.sell_script:​sh_power_on_off_vm|如何透過Shellscript去開啟與關閉你的VM?​]] 
-  * [[.sell_script:​sh_kill_proc|如何給予一個關鍵字去砍掉對應的Process?​]] 
-  * [[.sell_script:​searchPort|找尋被佔用的Port]] 
-  * [[.sell_script:​replaceFiles|替換檔案]] 
-  * [[.sell_script:​process_time|Process Time]] ​ 
-  * [[.shell_script:​setupAutologin|AutoLogin]] ​ 
-  * [[.shell_script:​replaceString|字串取代]] 
-  * [[.shell_script:​searchPortFromProcess|如何由PID去找它所佔用的port?​]] 
-  * [[.shell_script:​rebindAllSCSI|Rebind所有的SCSI hard drive]] ​ 
-  * [[.shell_script:​nc|nc - netcat]] ​ 
-  * [[.shell_script:​get_local_ip|取得IP Address]] included ipv4, ipv6 and cable status 
-  * [[.shell_script:​execution_time_measurement|測量執行時間]] 
-  * [[.shell_script:​bypass_invalid_options_of_getopts|Bypass invalid options of getopts]] 
-===== 暫存區 ===== 
-==== grep space ==== 
-並非所有系統grep都支援\s去偵測空白,可以使用[:​space:​]或[:​blank:​]當替代方案。(實測SLES11 grep 2.5.1不支援\s寫法) 
-  * [[http://​unix.stackexchange.com/​questions/​81916/​how-to-find-a-space-in-a-text-using-grep|how-to-find-a-space-in-a-text-using-grep?​]] 
-  * [[http://​linux.vbird.org/​linux_basic/​0330regularex.php|鳥哥 - 正規表示法與文件格式化處理]] 
-==== 確認行數 ==== 
-代表有15行。 
-<code bash> 
-> lspci | awk '{ print NR }' 
-1 
-2 
-.. 
-15 
-</​code>​ 
-==== Assign指令結果至變數 ==== 
-使用`號去包起來,以下範例會顯示123。 
-<code bash> 
-VAR=`echo 123` 
-echo $VAR 
-</​code>​ 
-假如指令有問題也要一併導至VAR,可以透過將stderr導向stdout:​ 
-<code bash> 
-VAR=`ff 2>&​1` 
-echo $VAR 
-</​code>​ 
- 
-==== 抓mac ==== 
-<code bash> 
-ifconfig | grep -o -E '​([[:​xdigit:​]]{2})(:​[[:​xdigit:​]]{2}){5}'​ 
-</​code>​ 
-==== 設dns ==== 
-<code shell> 
-systemd-resolve --set-dns=10.146.125.97 --interface enp3s0f0 
-</​code>​ 
- 
- 
- 
-===== Reference ===== 
-  * [[http://​bbs.chinaunix.net/​thread-452942-1-1.html|Shell基礎12篇]] 
-  * [[http://​bbs.chinaunix.net/​thread-218853-1-1.html|Shell 13問]] 
-  * [[http://​stackoverflow.com/​questions/​3701809/​how-to-detect-using-of-wildcard-asterisk-as-parameter-for-shell-script|看起來可以解決傳遞*參數問題]] 待試.. 
-  * [[http://​www.21andy.com/​blog/​20071121/​677.html|nohup]] 
-  * [[http://​stackoverflow.com/​questions/​8742783/​returning-value-from-called-function-in-shell-script|Function Call Return Value的三種方式]] 
-  * [[http://​www.jz123.cn/​text/​1633374.html|解決在Windows上修改後,跳行的問題]] 
-  * [[http://​www.cyut.edu.tw/​~dywang/​linuxProgram/​node20.html|awk工具]] 
-  * [[http://​shabirimam.wordpress.com/​2009/​03/​10/​adding-script-to-run-at-startup-or-shutdown/​|adding-script-to-run-at-startup-or-shutdown]] 
-  * [[http://​stackoverflow.com/​questions/​314675/​how-do-i-redirect-the-output-of-an-entire-shell-script-within-the-script-itself|Redirect the output of an entire shell script]] 
-  * [[http://​mark528.pixnet.net/​blog/​post/​7267334-shell-script%3A-%E6%8E%A7%E5%88%B6%E6%96%87%E5%AD%97%E9%A1%8F%E8%89%B2|控制文字顏色]] 
-  * [[http://​stackoverflow.com/​questions/​11952854/​how-to-check-if-the-variable-value-in-awk-script-is-null-or-empty|awk處理空字串]] 
-  * [[http://​www.thegeekstuff.com/​2010/​07/​perl-tcp-udp-socket-programming/​|Perl - How To: Perl TCP / UDP Socket Programming using IO::​Socket::​INET?​]] 
-  * [[http://​unix.stackexchange.com/​questions/​140750/​generate-random-numbers-in-specific-range|Gen Random value]] 
-  * [[http://​unix.stackexchange.com/​questions/​178899/​optimizing-logical-sector-size-for-physical-sector-size-4096-hdd|取得HD sector資訊的command]] (應還有smartctl) 
-  * [[http://​unix.stackexchange.com/​questions/​88281/​method-to-check-connectivity-to-other-server|how to test connection?​]] 
-  * [[http://​stackoverflow.com/​questions/​1761341/​awk-print-next-record-following-matched-record|Search Fields]] 
-  * [[http://​stackoverflow.com/​questions/​5152858/​how-can-i-measure-a-duration-in-seconds-in-a-linux-shell-script|how-can-i-measure-a-duration-in-seconds-in-a-linux-shell-script]] 
-  * [[http://​yenpai.idis.com.tw/​archives/​384-%E6%95%99%E5%AD%B8-centos-%E5%90%83%E4%BA%86%E6%88%91%E7%9A%84%E8%A8%98%E6%86%B6%E9%AB%94-cache-memory|清記憶體]] 
-  * [[http://​blog.xuite.net/​yipo.lin/​blog/​34151062-%E6%9F%A5%E7%9C%8BLinux%E7%A1%AC%E7%A2%9F%E8%A3%A1%E9%82%A3%E5%80%8B%E8%B3%87%E6%96%99%E5%A4%BE%E4%BD%94%E7%9A%84%E7%A9%BA%E9%96%93%E6%9C%80%E5%A4%9A|查資料夾使用硬碟空間大小]] 
-  * [[https://​unix.stackexchange.com/​questions/​345595/​how-to-set-ulimits-on-service-with-systemd|修改systemd service的ulimit]] 
-  * [[https://​unix.stackexchange.com/​questions/​118680/​difference-between-ulimit-n-and-proc-pid-limits|Difference between ulimit -n and /​proc/​$PID/​limits]] 
-==== sed ==== 
-  * [[http://​askubuntu.com/​questions/​76785/​how-to-escape-file-path-in-sed|escape file path with sed]] 
-==== network ==== 
-  * [[https://​unix.stackexchange.com/​questions/​441877/​identify-if-a-network-interface-is-a-veth-using-sys-class-net|辨別網卡是否為veth]]