I have an smb.conf file that is essentially of INI file format.
I'm trying to construct an awk 1-liner that will:
* check for the existence of the following line.
* If it doesn't exist, add it to the *end* of the [global] section.
* If it does exist, make sure it's as follows, or edit it to be as follows:
<tab>dfree command = /bin/dfree
I found this command that somewhat does what I need, but it's prepending a newline before adding the preferred line, so this:Sorry, I forgot to add what "this command" is:
[global]
...
log file = /var/log/samba/%m.log
guest account = guest
[samba]
path = /mount/samba
...
becomes this:
[global]
...
log file = /var/log/samba/%m.log
guest account = guest
dfree command = /bin/dfree
[samba]
path = /mount/samba
...
I'd like for it to look like this:
[global]
...
log file = /var/log/samba/%m.log
guest account = guest
dfree command = /bin/dfree
[samba]
path = /mount/samba
...
It also appears that it's not looking for and editing the line to match my preference (it's just appending):
[global]
...
log file = /var/log/samba/%m.log
guest account = guest
dfree command = /sbin/dfree
dfree command = /bin/dfree
[samba]
path = /mount/samba
...
This smb.conf file is part of a Linux distribution that is used on a hardware appliance. The contents and arrangement of items may change at any time, which is why I'm looking to do this the way I've described. I'm open to ideas if it can be done in a more efficient and reliable manner. Thanks in advance!
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 920 |
Nodes: | 10 (1 / 9) |
Uptime: | 98:33:53 |
Calls: | 12,189 |
Calls today: | 1 |
Files: | 186,527 |
Messages: | 2,237,396 |