Koozali.org: home of the SME Server

logonscript

jehu

logonscript
« on: February 27, 2003, 07:37:32 PM »
I edit my logonscript to map some extra drives and everything is working.  the only problem I have is all users get these mapped drives.  I only want admin to get the extra drives.
Can someone please tell me what I need to add to my script.

Thanks in advance,

Jehu.

Andy Parkinson

Re: logonscript
« Reply #1 on: February 28, 2003, 01:21:07 AM »
have a look at kixtart http://www.kixtart.org
This gives a great deal of flexibility with login scripts.
You can use IF and THEN statements to map drives if user is member of group or you can just have a different script for each user.

Alternatively map all the drives but make sure that the people you don't want to have these drives do not have read access to those Ibays. In win95/98/me and 2000 this will work fine but if you use xp the script will stop with an error

Steve Bush

Re: logonscript
« Reply #2 on: February 28, 2003, 11:40:31 PM »
To prevent the error in all cases use:
if exist \server\share net use g: \server\share

Andrej

Re: logonscript
« Reply #3 on: March 02, 2003, 10:22:57 AM »
Here is my NETLOGON.BAT (I think this can HELP)

======== BEGINING of NETLOGON.BAT==========

@echo off
@rem Lets see who is logging in ???
NET CONFIG | find "User">%TEMP%.\GETDATA.BAT
ECHO.e100'SET USERNAME='>%TEMP%.\SCR
FOR %%C IN (w q) DO ECHO.%%C>>%TEMP%.\SCR
debug %TEMP%.\GETDATA.BAT<%TEMP%.\SCR>NUL
CALL %TEMP%.\GETDATA.BAT
deltree /y %TEMP%.\SCR %TEMP%.\GETDATA.BAT>NUL

REM Time Sync
net time \server_name /set /yes
REM
REM Assign h: drive as home dir
net use h: /home

REM Attaching drives depends on username
if "andrej"=="%USERNAME%" GOTO andrej
if "pc1"=="%USERNAME%" GOTO classroom
if "biolog1"=="%USERNAME%" GOTO biolog
if "biolog2"=="%USERNAME%" GOTO biolog
if "biolog3"=="%USERNAME%" GOTO biolog
if "biolog4"=="%USERNAME%" GOTO biolog
if "biolog5"=="%USERNAME%" GOTO biolog
if "biolog6"=="%USERNAME%" GOTO biolog

:andrej
net use i: \server_name\inf
goto end


:classroom
net use i: \server_name\inf\files
goto end

:biolog
net use i: \server_name\bio
goto end

:end

======== END of NETLOGON.BAT==========


With this file you can control all your users and shares. The same can be aranged for computers name if you want!!!

Cheers,

Andrej

Greg Allt

Re: logonscript
« Reply #4 on: March 15, 2003, 07:12:20 PM »
here is what I use on my server

this file is in the path

/home/netlogon/bin

and is called

logonscript.pl

it creates a file in the
/home/netlogon
folder that consists of the account name with the extension .bat

ie abby.bat

This bat file is run automatically at logon time by the client computer when it is set to use domain logons.

The file is then erased automatically after logon is completed.


>>> example >>>>

#!/usr/bin/perl

sub ingroup($)
{
  my $group=shift;
  my $result=0;
  my $lcuser=lc($ARGV[0]);

  open (FD,"  while ()
  {
    my $data=$_;
    if ($data =~ /$group/)
    {
      if ($data =~ /$lcuser/)
      {
        $result=1;
        last;
      }
    }
  }
  close FD;
  return $result;
}

# -- create logon script with user's name as a bat file
$Server=e-smith-server

open LOGON, ">/home/netlogon/$ARGV[0].bat";

print LOGON "echo Welcome $ARGV[0] to the Computer Network\r\n";
print LOGON "echo.\r\n";
print LOGON "echo set user=$ARGV[0]\r\n";
print LOGON "rem $ARGV[0] logged into $ARGV[1]\r\n";
print LOGON "rem \@echo off \r\n";

# -- automatically map h to the user's home directory
      print LOGON "NET USE H: \$Server\$ARGV[0]\r\n";

# -- map j: for members of the group jobs to the share jobs
      if (&ingroup("jobs")) {print LOGON "NET USE J: \$Server\jobs\r\n"};

# -- map I for members of the group sysbase
      if (&ingroup("sybase")) {print LOGON "NET USE I: \$Server\SYBASE\r\n"};

# -----------------------------------------
# --- map the common shares
# -----------------------------------------
   # -- give everyboy the drive M on the computer server2
         print LOGON "NET USE M: \server2\music\r\n";

   # -- map everyon to the application directory
         print LOGON "NET USE X: \$Server\apps\r\n";

   # -- synchronize everyones time
         print LOGON "NET TIME \$Server /SET /YES";

#  ---- user specific example
# if username is abby, map her to the music-rw share
    if (ARGV[0] = "ABBY")
    {
         print LOGON "NET USE M: /d";
     print LOGON "NET USE m: \server2\music-rw\r\n";
    };
close LOGON;

chris snow

Re: logonscript
« Reply #5 on: March 30, 2003, 06:31:38 PM »
Hi Greg,

I tried your script but I can't get it working.  When does loginscript.pl get run?  Do I need to modify smb.conf?

Thanks,

Chris

glenn

Re: logonscript
« Reply #6 on: April 01, 2003, 08:34:14 AM »
I had the same problem as Chris. Is there a setting somewhere to tell Samba that logonscript.pl needs to be run before netlogon.bat is sent to the workstation?

Glenn

glenn

Re: logonscript - a solution
« Reply #7 on: April 01, 2003, 11:06:36 AM »
I found the clue I needed at:
http://itc.musc.edu/cgi-bin/twiki/view/Linux/SambaPDC

- Edit /etc/e-smith/templates/etc/smb.conf/11logonScript
- change 'netlogon.bat' to '%u.bat'
- edit /etc/e-smith/templates/etc/smb.conf/61netlogonshare
- add a line after the 'browseable' line as follows:
   root preexec = /home/netlogon/bin/logonscript.pl %u
- rebuild the smb.conf file:
   /sbin/e-smith/expand-template /etc/smb.conf
- reboot your server (or restart samba)

I think that's everything. Hope this helps.

Glenn

Chris Snow

Re: logonscript
« Reply #8 on: April 01, 2003, 10:29:17 PM »
Works great - thank you!

Regards,

Chris

Tom Carroll

Re: logonscript
« Reply #9 on: May 05, 2003, 01:04:49 PM »
Just so others who read this know, you can specify a netlogon.bat file specific for each machine and user by using the expandable variables %m (for machine name) and %u (for user name) in the 11logonScript template fragment.

I specifically built netlogon.bat files specific to users and what machine they log onto, but I believe the above mentioned perl script may consolidate everything into one file.  However, this works for simple problems...  For example:

machine1-user1-netlogon.bat
machine2-user1-netlogon.bat
machine1-user3-netlogon.bat

Remember, if you specify the %m-%u-netlogon.bat in your template fragment, you will need to create a specific batch file for each machine, or your mappings, etc. will not occur, unless you do something creative with another script.

Greg Allt

Re: logonscript - a solution
« Reply #10 on: July 29, 2003, 09:14:36 PM »
Oops

sorry about that - guess I omitted some details.  Also have to make sure the logonscript.pl is chmod +x so it is an executable.

For those who are still trying this

it can be tested by running

./logonscript.pl

which will then create a file in the netlogon directory called

.bat

that file should have all the shares mapping in it

also, for mappings based on individual users, I made an error, it should hav eq rather than ~=