[Samba] Re: root prexec/postexec & login scripts

Ulrich Kohlhase Ulrich.Kohlhase at t-online.de
Tue Oct 29 01:33:12 GMT 2002


In case you still need a configurable login script ...

Add to [netlogon] share:
root preexec = perl /usr/local/samba/lib/genlogon.pl %u %g %m
root postexec = perl /usr/local/samba/lib/genlogoff.pl %u

Good luck,


# genlogon.pl
# smb.conf:
# root preexec = genlogon.pl %u %g %m
use Time::localtime;

($username, $groupname, $pcname) = @ARGV;

my $tm = localtime();
$datestring = sprintf "%02d.%02d.%04d",$tm->mday, $tm->mon + 1,
$tm->year + 1900;

$logdateiname = sprintf ">>/usr/local/samba/var/netlogon.log";
open (logfile, $logdateiname);
printf logfile  "%s - %02d:%02d:%02d : User \"%s\" \t group \"%s\"
logs in %s \n", $datestring, $tm->hour, $tm->min
, $tm->sec, $username, $groupname, $pcname;
close logfile; 

# Start login script:
open LOGON, ">/usr/local/samba/netlogon/$username.bat";
print LOGON "\@ECHO OFF\r\n";

# Home shares
print LOGON "NET USE Z: \\\\$server\\$username /persistent:no\r\n";

# Shares for individual groups
if ($groupname eq "GROUP" || $groupname eq "group")
       print LOGON "NET USE X: \\\\$server\\SHARE1 /persistent:no\r\n";
       print LOGON "NET USE Y: \\\\$server\\SHARE2 /persistent:no\r\n";

# Close output file
close LOGON;


# genlogoff.pl

system("rm /usr/local/samba/netlogon/$ARGV[0].bat");


More information about the samba mailing list