
我想知道是否有任何可在 bash 腳本中使用的工具可以輕鬆地讓您操縱(新增、刪除、更新)conf 檔案內的指令?
例如,fail2ban.conf 已分組指令,每個指令都在自己的部分下。
[proftpd]
enabled = true
port = ftp,ftp-data,ftps,ftps-data
[postfix]
enabled = true
port = smtp,465,submission
而 pagespeed.conf 有混合指令,有些在自己的部分中,有些則排列在各處。
<Location /pagespeed_admin>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
SetHandler pagespeed_admin
</Location>
<Location /pagespeed_global_admin>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
SetHandler pagespeed_global_admin
</Location>
ModPagespeedMessageBufferSize 100000
ModPagespeedStatisticsLogging on
ModPagespeedEnableCachePurge on
ModPagespeedPurgeMethod PURGE
ModPagespeedFileCacheSizeKb 2048000
ModPagespeedFileCacheCleanIntervalMs 3600000
ModPagespeedFileCacheInodeLimit 500000
你明白了。
是否有任何工具允許您:例如操作fail2ban.conf 的“proftpd”部分中的“enabled”指令?
或操縱 pagespeed.conf 的「Location /pagespeed_admin」部分中的「Allow from」指令?
或操縱 pagespeed.conf 的「無特定」部分中的「ModPagespeedMessageBufferSize」指令?
謝謝
答案1
不,原因很簡單,設定檔可能使用的格式太多。我認為,你能做的最好的事情就是使用文字處理工具來推出你自己的。
可能有針對某些格式(例如 JSON)的庫,但工具作者可以自由使用他們喜歡的任何格式,因此通用工具是不可能的。為了說明這一點,以下是一些conf檔案中的幾行:
emacs
;; Are we running XEmacs or Emacs? (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)) ;; disable menu bar when running in terminal (when (not (display-graphic-p)) (menu-bar-mode -1)) ;;My libraries, ebib, wordcount etc (add-to-list 'load-path "~/.emacs-lisp/")
六
highlight Normal guibg=grey90 highlight Cursor guibg=Green guifg=NONE highlight lCursor guibg=Cyan guifg=NONE highlight NonText guibg=grey80 highlight Constant gui=NONE guibg=grey95 highlight Special gui=NONE guibg=grey95
著色
#--------------------------------------------- # BACKGROUND AND BORDER #--------------------------------------------- # general panel settings rounded = 7 border_width = 2 #background_color = #B4B2B2 10 background_color = #000000 30 border_color = #8F0004 0
虛擬LC
# Trigger button (string) #gestures-button=left [motion] # motion control interface [oldrc] # Remote control interface # Show stream position (boolean) rc-show-pos=0
sshd
AuthorizedKeysFile .ssh/authorized_keys ChallengeResponseAuthentication no UsePAM yes
等等等等
答案2
不是真的,但您可以為特定的配置佈局建立一些東西。就像是
sed -E "/\[proftpd]/,/\[/{s/(enabled\s*=\s*).*/\1false/}" input.file
例如,可以將其設計為更改fail2ban.conf 的函數。
如果有趣的話我可以擴充。