我正在尝试创建一个 bash 脚本,该脚本将读取 samba 配置,遍历不同的“部分”并在设置变量时采取行动
这是一个示例配置:
[global]
workgroup = METRAN
encrypt passwords = yes
wins support = yes
log level = 1
max log size = 1000
read only = no
[homes]
browsable = no
map archive = yes
[printers]
path = /var/tmp
printable = yes
min print space = 2000
[music]
browsable = yes
read only = yes
path = /usr/local/samba/tmp
[pictures]
browsable = yes
read only = yes
path = /usr/local/samba/tmp
force user = www-data
这是我想做的事情(我知道这种语法是一种真正的语言,但它应该给你一个想法:
#!/bin/sh
#
CONFIG='/etc/samba/smb.conf'
sections = magicto $CONFIG #array of sections
foreach $sections as $sectionname #loop through the sections
if $sectionname != ("homes" or "global" or "printers")
if $force_user is-set
do something with $sectionname and with $force_user
endif
else
do something with $sectionname
endelse
endif
endforeach