AD and Folder Redirection

New Contributor II

Hi Folks,

I'm a very new systems engineer and my scripting skills is pretty much -1 to Zero.

I have an issue at a school I have been directed for Casper Support.

They have a setup where Macs are bound to AD and user home folders, i.e. desktop, documents, downloads, are being redirected to a network share. This has been setup by a previous engineer, no longer works at the school.

The problem is an intermittent problem where sometimes, students do not have access to their desktops, the files don't appear on the desktop. Most times to fix the issue is to launch finder and click on "desktop" on the side bar. The School's network admin states that it could be a timing issue or something within the script that skips the loop.. something along those lines.

Because I suck at scripting and still learning, I hope you guys can help me out and check to see if there are some issues within this script.

# 23/11/2012 Cranbrook School - v1.8 - Folder Redirection Script
# 24/01/2014 Updated for Casper Deployment

#USER=`ls -la /dev/console | cut -d " " -f 4`
#WSERVER=`ps ax | grep -i WindowServer | grep -v grep | cut -d " " -f 2`
MYDOCDIR="/Volumes/net/My Documents"
MYPICDIR="/Volumes/net/My Documents/My Pictures"
MYVIDDIR="/Volumes/net/My Documents/My Videos"
MYMUSDIR="/Volumes/net/My Documents/My Music"

#ECHO ----------------- Starting Script -------------------

sleep 10

#ECHO ----------------- Checking Folders ---------------

if [ -d "$MYDOCDIR" ]; then
    echo "$MYDOCDIR is Available!"
    echo "$MYDOCDIR is Empty"

if [ -a "$MYDSKDIR" ]; then
    echo "$MYDSKDIR is Available!"
    echo "$MYDSKDIR is Empty" 

if [ -d "$MYPICDIR" ]; then
    echo "$MYPICDIR is Available!"
    echo "$MYPICDIR is Empty"

if [ -d "$MYVIDDIR" ]; then
    echo "$MYVIDDIR is Available!"
    echo "$MYVIDDIR is Empty"

if [ -d "$MYMUSDIR" ]; then
    echo "$MYMUSDIR is Available!"
    echo "$MYMUSDIR is Empty"

if [ -d "${MYDSKDIR}" -a -d "${MYDOCDIR}" ]; then
     echo "$MYDSKDIR and $MYDOCDIR are both Available!"
    echo "####Your Account has a Problem, Please Visit IT Dept####"
    exit 1
#    say "Your Account has a Problem! Please see Steve @ I T Department" 
    sleep 5
#    sudo kill -HUP $WSERVER


#ECHO ----------------- Redirecting Folders ---------------
#Wait for OS X to Create Local Homes
sleep 4

rm -Rf "/Users/$USER/Documents"
ln -sFfh "/Volumes/net/My Documents" "/Users/$USER/Documents"

rm -Rf "/Users/$USER/Desktop"
ln -sFfh /Volumes/net/Desktop "/Users/$USER"

rm -Rf "/Users/$USER/Pictures"
ln -sFfh "/Volumes/net/My Documents/My Pictures" "/Users/$USER/Pictures"

rm -Rf "/Users/$USER/Movies"
ln -sFfh "/Volumes/net/My Documents/My Videos" "/Users/$USER/Movies"

rm -Rf "/Users/$USER/Music"
ln -sFfh "/Volumes/net/My Documents/My Music" "/Users/$USER/Music"

rm -Rf "/Users/$USER/Downloads"
ln -sFfh "/Volumes/net/My Documents/Downloads" "/Users/$USER/Downloads"

ECHO ----------------- Completed Script -------------------
killall Finder
#killall Terminal
exit 0

Kind Regards,



Honored Contributor II
Honored Contributor II


The script doesn't seem to have anything particularly wrong with it, although its not a method I generally like to use.

The path to the network home doesn't look right at the top (/Volumes/net). "net" would normally be the name of the users network home folder. Although this might be correct in your case.

$USER would only work is the script is being run as the logging in user. What method is being used to trigger the script?

New Contributor II

The login script is triggered by a launch daemon found in /Library/LaunchAgent/ as folder redirection.plist. The folder redirection policy is triggered every checkin which is 15 minutes.

It seems to work fine on our test accounts. After logging in as the user, it did take about 10 seconds for the folders to redirect. Logging in and out as another user, then back in as the first, the folder is redirected.

Its just frustrating that it is intermittent