Shell Script
ShellScript有多強大我不必贅述。我所撰寫的文章都是以前遇到問題所想到的解決方法,也許不是每個做法都很完美,畢竟都是遇到的東西越多,才越能學習到更多更精闢的語法。
Article List
- 取得IP Address included ipv4, ipv6 and cable status
暫存區
grep space
並非所有系統grep都支援\s去偵測空白,可以使用[:space:]或[:blank:]當替代方案。(實測SLES11 grep 2.5.1不支援\s寫法)
確認行數
代表有15行。
> lspci | awk '{ print NR }' 1 2 .. 15
Assign指令結果至變數
使用`號去包起來,以下範例會顯示123。
VAR=`echo 123` echo $VAR假如指令有問題也要一併導至VAR,可以透過將stderr導向stdout:
VAR=`ff 2>&1` echo $VAR
抓mac
ifconfig | grep -o -E '([[:xdigit:]]{2})(:[[:xdigit:]]{2}){5}'
設DNS
Ubuntu很搞怪,不能直接改resolve.conf:
systemd-resolve --set-dns=10.146.125.97 --interface enp3s0f0
Reference
- 看起來可以解決傳遞*參數問題 待試..
- 取得HD sector資訊的command (應還有smartctl)