awk 備忘

列出 UID > 499 的帳號及 UID
$ awk ‘BEGIN {FS=”:”}; $3 > 499 {print $1″t”$3}’ /etc/passwd
core    500
systemd-coredump        998

去除標題
$ ps a | awk ‘NR!=1 {print $0}’ | head
 1237 tty1     Ss     0:00 /bin/login —
 1238 ttyS0    Ss+    0:06 /sbin/agetty –keep-baud 115200 38400 9600 ttyS0 vt220
 1294 tty1     S+     0:00 -bash
14202 pts/0    Ss     0:00 -bash
14264 pts/0    R+     0:00 ps a
14265 pts/0    S+     0:00 awk NR!=1 {print $0}
14266 pts/0    S+     0:00 head[@more@]
列出第 2 行到第 5 行
$ ps a | awk ‘(NR>1 && NR<=5){print $0}’ | head
 1237 tty1     Ss     0:00 /bin/login —
 1238 ttyS0    Ss+    0:06 /sbin/agetty –keep-baud 115200 38400 9600 ttyS0 vt220
 1294 tty1     S+     0:00 -bash
14202 pts/0    Ss     0:00 -bash

列出某一使用者的 UID
awk -F “:” ‘/docker/ {print $3}’ /etc/passwd
996

區分大小寫
$ awk -F”:” ‘BEGIN{IGNORECASE=1}{if($1==”core”){print $3}}’ /etc/passwd
500

計算行數
$ awk ‘END{print NR}’ /etc/profile
59
 $ wc -l /etc/profile
59 /etc/profile
$ sed -n ‘$=’ /etc/profile
59
 $ grep -c “” /etc/profile
59

計算空白行數
# cat blankline.awk
#!/usr/bin/awk
/^$/ {
  x += 1
}
END {
     print x;
}

# awk -f blankline.awk /etc/profile
11

NAS4Free – 更改 IP

安裝 NAS4Free 時是使用 DHCP Server,直接取得 IP,如果想要更換成其它固定的 IP 設定方法。
1. 原先的 IP 是 192.168.1.250,選擇 2 Configure Network IP Address

[@more@]2. 不使用 DHCP Server 取得 IP

3. 設定要使用的 IP

4. 設定子網路遮罩 Subnet mask

5. 設定 Gateway

6. 設定 DNS Server

7. 不設定 IPv6

8. IP 已經改成 192.168.1.99

OpenMediaVault – 使用 grive 同步檔案到 Google Drive(成功)

參考網頁:
Grive2 — YourcmcWiki
GitHub – vitalif/grive2: Google Drive client with support for new Drive REST API and partial sync

1.安裝所需套件
# apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev pkg-config

2. 下載 grive Source Code
# git clone https://github.com/vitalif/grive2
Cloning into ‘grive2’…
remote: Counting objects: 3914, done.
remote: Total 3914 (delta 0), reused 0 (delta 0), pack-reused 3914
Receiving objects: 100% (3914/3914), 1.05 MiB | 364.00 KiB/s, done.
Resolving deltas: 100% (2565/2565), done.
Checking connectivity… done.[@more@]3. 進行編譯
# cd grive2
# mkdir build
# cd build
# cmake ..
— Found libgcrypt: -lgcrypt
— Boost version: 1.55.0
— Found the following Boost libraries:
—   program_options
—   filesystem
—   unit_test_framework
—   regex
—   system
— Found libbfd: /usr/lib/libbfd.so
— Found CppUnit: /usr/lib/x86_64-linux-gnu/libcppunit.so
— Could NOT find ZLIB (missing:  ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
— Found PkgConfig: /usr/bin/pkg-config (found version “0.28”)
— checking for module ‘yajl’
—   found yajl, version 2.1.0
— Building unitary tests along with the library and the binary
— Boost version: 1.55.0
— Found the following Boost libraries:
—   program_options
— Configuring done
— Generating done
— Build files have been written to: /root/grive2/build

4. 進行安裝
# make -j4
# make install
Install the project…
— Install configuration: “”
— Installing: /usr/local/bin/grive
— Installing: /usr/local/share/man/man1/grive.1

5. 取得 Google Drive 授權碼
# cd /home/t850008
# /usr/local/bin/grive -a

6. 進行同步
# /usr/local/bin/grive -p /home/t850008

7. 進行工作排程
# crontab -e
*/5 * * * * /usr/local/bin/grive -p /home/t850008 > /dev/null 2>&1

OpenMediaVault – 使用 grive 同步檔案到 Google Drive(失敗)

參考文件:在 Linux 中使用 Grive 指令工具同步 Google 雲端硬碟(Drive)上的檔案 – G. T. Wang
1. 安裝 grive
# apt-get update
# apt-get install grive

2. 先開啟瀏覽器登入到要同步的 Google Drive 帳號:

[@more@]3. 切換到要同步的目錄,並進行設定
# cd /home/t850008
# grive -a

4. 在下方產生網址

5. 將產生的網址,貼到瀏覽器網址列,按  Enter 鍵執行

6. 選擇 允許

7. 將產生的 授權碼 複製起來

8. 將產生的 授權碼 貼在下方,按  Enter 鍵執行

9. 執行畫面

10. 執行 grive 進行同步,但無法同步

11. 移除 grive
# apt-get remove –purge grive

NAS4Free 系統安裝篇

NAS4Free 下載網站:https://sourceforge.net/projects/nas4free/files/
1. 開機畫面
[@more@]2. 文字介面功能表

3. 選擇 9Install/Upgrade from LiveCD/LiveUSB

4. 視所需功能來選擇, Install ‘Full’ OS/MBR on HDD/SSD + DATA + SWAP

5. 硬碟分成三個部分 OS / SWAP / DATA

6. 光碟機 cd0

7. 硬碟 da0

8. OS 分割區大小,這裡依預設值

9. SWAP 分割區大小,這裡依預設值

10. 硬碟分割及安裝系統

11. 安裝完畢,按 Enter

12. 選擇 7Reboot Server

13. 選擇 Yes 重新開機

14. 預設帳號密碼 admin / nas4free

15. 英文管理介面

16. 選擇 System / General

17. 將語言由 English

18. 改成 Chinese(Traditional) 將時區改成 Asia/Taipei

19. 管理介面已經改成正體中文

20.

OpenMediaVault 系統安裝篇

OpenMediaVault 下載網頁:https://sourceforge.net/projects/openmediavault/files/
1. 光碟開機畫面,請選擇 Install
[@more@]2. 安裝時使用的語言

3. 選擇 Other

4. 設定亞洲 Asia

5. 設定國家 Taiwan

6. 設定 default locale

7. 設定鍵盤

8. 設定 Host name

9. 設定 Domain name

10. 設定 root 管理者密碼

11. 複製系統到硬碟

12. 設定套件更新站台所在國家

13. 設定套件更新站台

14. 設定是否使用 Proxy

15. 設定 apt

16. 安裝 GRUB

17. 設定系統環境

18. 安裝完成

19. 系統的 IP

20. 預設登入的帳號及密碼:admin / openmediavault

21. 中文化的管理介面

22.