SAMBA Scripts

Table of Contents

1. Simple Scripts
1.1. Terminating and restarting Samba
1.2. Post-install
2. Shell script to produce your windows logon scripts
Ignore these links

This is a part of my Samba website.  I can be reached under

1. Simple Scripts

These have been written for linux and bash/perl.  I keep mine in /root/bin and have their permissions set to 0700.  If you use them, you do so for your own convenience and at your own risk. The command killproc is not universally available; killall seems to work in a similar fashion on some systems - although it apparently kills all processes on a Sun! (why would anyone want to implement a function like that?)

1.1. Terminating and Restarting Samba

#! /bin/sh
# Kill and restart Samba
echo -n "Shutting down Samba: "
killproc -TERM /usr/sbin/nmbd
killproc -TERM /usr/sbin/smbd
echo -n "Hit XMIT to delete logs and restart"
rm /var/log/samba/log.*
echo -n "Restarting Samba "
/usr/sbin/nmbd -D
/usr/sbin/smbd -D
echo " done"
As you will see, it also kills the logfiles left by the previous version.  You may have to change some names because your Samba executables and logfiles are likely to be somewhere else.

 The 2 lines:

     echo -n "Hit XMIT to delete logs and restart"
and  read
are there because I sometimes want to change something while Samba is down.

As an alternative under Linux, you could try the two lines:

killall -HUP smbd
killall -HUP nmbd
(from Michael Maclean) although these do not delete the logfiles.

1.2. Post-install

This runs after make installman or make install and it is needed for each new release.  It normally only complains that "/usr/man/allman" does not exist.
#!/usr/bin/perl -w
# This work of art copies the Samba man-pages from $base_man to
# $dest_man, copies that were previously in the @rm_man directories
# are deleted.
# As Is, it is tailored for SuSE.  It may well work under on other
# systems (with Perl) but USE IT ENTIRELY AT YOUR OWN RISK!
# (This was my second-ever Perl script so be tolerant)

use strict; use File::Copy;
my (@base_sub, @base_top, @del_list, @rm_man, $cp, $i, $base, $bsub, $del, $rm); # my $base_man = "/usr/local/samba/man";  # copy from here my $dest_man = "/usr/local/man";        # to beneath here my @rm_in = ("/usr/share/man","/usr/share/man/allman"); # delete beneath here # As far as I know, /usr/share/man/allman only existed under SuSE # # Check that the directories actually exist. Insist on $base_man, # $dest_man and at least one @rm_man value. # if (! (-d $dest_man)) {    die "Could not find $dest_man ($!)";    } foreach $i (@rm_in) {    if (-d $i) {       push @rm_man, $i;    }    else {       print "Directory $i does not exist, ignored\n"; }  } if (@rm_man == 0) {    die "Could not find any of: @rm_in - $!";    } chdir($base_man) || die "Could not get to $base_man ($!)"; opendir BASE_MAN, $base_man; @base_top = grep !/^\.\.?$/, readdir BASE_MAN; closedir BASE_MAN; # #        Loop through /$base_man looking for subdirectories # foreach $base (@base_top) {    opendir BASE_SUB, $base_man."/".$base;    @base_sub = grep !/^\.\.?$/, readdir BASE_SUB;    closedir BASE_SUB;    foreach $bsub (@base_sub) {       $cp = "$base/$bsub";       foreach $rm (@rm_man) {          @del_list = <$rm/$cp*>;          if (@del_list != 0) { #           print "unlink @del_list \n" ; #           $del= unlink @del_list || print "rm @del_list Failed: $!\n";             $del = unlink @del_list ;             if ($del == 0) {print "rm @del_list Failed: $!\n" };       }  }       copy("$base_man/$cp", "$dest_man/$cp") || print "cp $base_man/$cp $dest_man/$cp Failed: $!\n"; }  }

Since this script gets somewhat mangled by the conversion to HTML, here it is as .TXT.
*** End of the Document ***