Manually Mounting AD Home folders

AdamH
New Contributor II

Does anyone have the script (or any other way) to manually invoke the mounting of the home folder associated with a network user's home folder?

So we have User-Certificates for access to our in-house WiFi. Since its user-based, the wifi doesn't connect until the user is logged in, by that time the hook for mounting the home folder has past. We also have several home folder servers, so its not as simple as getting the user's username and adding it to a path.

8 REPLIES 8

davidacland
Honored Contributor II
Honored Contributor II

Hi,

Here's a link to our script on Github. If you want the user to initiate it, I would put it into an Applescript app for them to click on.

myhttps://github.com/amsysuk/public_scripts/blob/master/mount_SMBHome/mounthome.sh

nessts
Valued Contributor II
#!/usr/bin/perl -w

# config runtime environment
use strict;
use Sys::Syslog;

my $console = "/dev/console";
my $consoleuser = getpwuid((stat $console)[4]);
my $mtpt = "/Volumes/$consoleuser";
my $SMBHOME=`dscl "/Active Directory/YOURDOMAIN/All Domains" read Users/$consoleuser SMBHome`;
my $test = $mtpt;
my $count = 0;

(my $progname =$0) =~ s#.*/##;
$ENV{PATH} = '/bin:/usr/bin:/usr/sbin:/sbin';
umask 0022;

main:
openlog $progname, undef, 'user';
chomp($SMBHOME);
$SMBHOME =~ s#\#/#g;
$SMBHOME = (split ' ', $SMBHOME)[-1];
#look for the directory if it exists it could already be mounted or something else so try user+number
while ( -e $test) {
        $count++;
        $test = $mtpt . $count;
}
$mtpt = $test if ($count > 0);
syslog('notice', "making mount point %s", $mtpt);
system("mkdir  "$mtpt"");
my $rc = system("mount_smbfs "$SMBHOME" "$mtpt"");
if ($rc) {
        syslog('notice', "Mount failed removing directory %s", $mtpt);
        system("rmdir $mtpt");
}
closelog;

nessts
Valued Contributor II

You could modify it to wait for a network to exist and ping the server before trying to mount as well. This is assuming they are on the right network

AdamH
New Contributor II

Hey, thanks for the help!
I have to admit I'm not a strong scripter...and even less strong in pearl.

Todd, I tried your script and changed ERICSSON to our domain.
When I ran the script in the terminal I got a few errors:

line 4: use: command not found
line 5: use: command not found
line 7: my: command not found
line 8: syntax error near unexpected token `('
line 8: `my $consoleuser = getpwuid((stat $console) [4]);'

..and when I say 'less strong at pearl' I mean..never used it....

nessts
Valued Contributor II

i am guessing that the first line in your script is not

#!/usr/bin/perl -w

nessts
Valued Contributor II

sorry for the formatting mess on the last entry, that has been fixed.

AdamH
New Contributor II

Not knowing Pearl I left the first line commented out as you posted it. Should the # be left out?

nessts
Valued Contributor II

All scripts need the hash and the exclamation point at the beginning of them to tell the shell what interpreter to run. So while it looks like a comment it is not