[Samba] Looking for a script to add/remove multiple shares from smb.conf

Goetz Rieger goetz.rieger at suse.de
Wed Jul 31 06:42:02 GMT 2002


On Tue, 30 Jul 2002 08:05:14 -0500
drew.arthur at mail.sprint.com wrote:

> I would like to easily add/remove share entries in the smb.conf file 
> without removing or deleting lines that are not associated with that 
> section. I use SWAT for single shares.  

Ok: Quick and dirty, but seems to work. Give it a try, but please be
careful. It leaves two blank lines, but that should not matter. And it
would delete shares which are commented out and which follow a share to




my $smbconf="smb.conf";
my @shares_to_delete=qw(printers homes);

open(SMBCONF, $smbconf);
open(SMBCONFNEW, ">smb.conf.new");

$a=join("", <SMBCONF>);

foreach $share (@shares_to_delete) {
$a =~ s/^\[$share\]([^^][^\[])*//gm;

print SMBCONFNEW "$a";

More information about the samba mailing list