LanSchool - Dynamic Class Lists from SIS

hansonr55
New Contributor

I'm looking for the best way to have MBAs read two .csv files from an SMB share. We are deploying LanSchool which will read dynamically created class lists.

My problem is that if I map that share, everything works as intended, but whenever a teacher leaves the network (1:1 so they take their machines home) the mounted shares disconnect and need to be remounted.

I want this to be automated so that teachers don't have to remount the share themselves prior to running LanSchool when they come in every day.

Any ideas?

3 REPLIES 3

elund
New Contributor III

We use a shared Google Drive folder to sync the .csv file to the teachers machines.

Ed

Kennedy
New Contributor II

I have scripts create the CSV files on a web server and then scripts running at check in on the machines that download those CSVs. Works offsite too.

Cheers,
Gav

Kennedy
New Contributor II

Our script that runs on the machines is as follows:

#!/bin/bash

#log the output of the script to the jamf.log for easy viewing
logfile=/var/log/jamf.log;
exec >> $logfile 2>&1;




#------------------------------     
#-------BEGIN VARIABLES--------
#------------------------------ 

scriptname="get_latest_lanschool_classes.sh";
classesbyteacherlink="http://school.webserver/downloads/lanschool/ClassesByTeacherLoginName.csv";
studentsforclasslink="http://school.webserver/downloads/lanschool/StudentsForClassByLoginName.csv";
localfolder="/Library/BCGS/LanSchool";

#------------------------------     
#-------END VARIABLES----------
#------------------------------



echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:   "
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: ------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: --- Starting $scriptname"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:   "
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Script variables:" 
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:    $classesbyteacherlink =  $classesbyteacherlink"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:    $studentsforclasslink =  $studentsforclasslink"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:    $localfolder =  $localfolder"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:"

#make the /Library/BCGS folder
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Making /Library/BCGS folder."
if [ -d "/Library/BCGS" ]
then
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Skipped making /Library/BCGS folder - already exists."
else
    mkdir /Library/BCGS >/dev/null 2>/dev/null
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Made /Library/BCGS folder."
fi

#make the LanSchool folder
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Making the /Library/BCGS/LanSchool folder."
if [ -d "/Library/BCGS/LanSchool" ]
then
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Skipped making /Library/BCGS/LanSchool folder - already exists."
else
    mkdir /Library/BCGS/LanSchool >/dev/null 2>/dev/null
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Made /Library/BCGS/LanSchool folder."
fi

blDownloadFailed="false";

#download both CSV files as temp, then check they they downloaded and are not 0 bytes in size
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Downloading $classesbyteacherlink."
curl "$classesbyteacherlink" -o "/Library/BCGS/LanSchool/classesbyteachertemp.csv" >/dev/null 2>/dev/null
if [ -f "/Library/BCGS/LanSchool/classesbyteachertemp.csv" ]
then
    #file downloaded successfully
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Download completed successfully."
else
    #file download failed
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Download failed."
    blDownloadFailed="true"
fi

echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Downloading $studentsforclasslink."
curl "$studentsforclasslink" -o "/Library/BCGS/LanSchool/studentforclasstemp.csv" >/dev/null 2>/dev/null
if [ -f "/Library/BCGS/LanSchool/studentforclasstemp.csv" ]
then
    #file downloaded successfully
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Download completed successfully."
else
    #file download failed
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Download failed."
    blDownloadFailed="true"
fi

blDeleteFailed="false";

if [ "$blDownloadFailed" == "false" ]
then
    #looks like both downloads completed successfully, so lets proceed
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Both files downloaded successfully, proceeding."

    #delete the real files
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Deleting /Library/BCGS/LanSchool/ClassesByTeacherLoginName.csv."
    if [ -f "/Library/BCGS/LanSchool/ClassesByTeacherLoginName.csv" ]
    then
        rm "/Library/BCGS/LanSchool/ClassesByTeacherLoginName.csv"
        if [ ! -f "/Library/BCGS/LanSchool/ClassesByTeacherLoginName.csv" ]
        then
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Deleted file successfully."
        else
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Failed to delete file."
            blDeleteFailed="true"
        fi
    else
        echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - File does not exist, skipping."
    fi

    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Deleting /Library/BCGS/LanSchool/StudentsForClassByLoginName.csv."
    if [ -f "/Library/BCGS/LanSchool/StudentsForClassByLoginName.csv" ]
    then
        rm "/Library/BCGS/LanSchool/StudentsForClassByLoginName.csv"
        if [ ! -f "/Library/BCGS/LanSchool/StudentsForClassByLoginName.csv" ]
        then
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Deleted file successfully."
        else
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Failed to delete file."
            blDeleteFailed="true"
        fi
    else
        echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - File does not exist, skipping."
    fi

    if [ "$blDeleteFailed" == "false" ]
    then
        #looks like both files deleted sucesffully, so lets proceed
        #copy the temp files to the real file location
        echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Copying temp files to real locations."
        cp "/Library/BCGS/LanSchool/classesbyteachertemp.csv" "/Library/BCGS/LanSchool/ClassesByTeacherLoginName.csv"
        if [ -f "/Library/BCGS/LanSchool/ClassesByTeacherLoginName.csv" ]
        then
            #file copied succesfully
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Copied to ClassesByTeacherLoginName.csv successfully."
        else
            #file copy failed
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Copy to ClassesByTeacherLoginName failed."
        fi

        cp "/Library/BCGS/LanSchool/studentforclasstemp.csv" "/Library/BCGS/LanSchool/StudentsForClassByLoginName.csv"
        if [ -f "/Library/BCGS/LanSchool/StudentsForClassByLoginName.csv" ]
        then
            #file copied succesfully
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Copied to StudentsForClassByLoginName.csv successfully."
        else
            #file copy failed
            echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Copy to StudentsForClassByLoginName failed."
        fi

    else
        echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Deleting of the files failed, quitting script."
    fi

else
    #there was a failed download, lets get out
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: One of the downloads failed, quitting script."
fi

#remove temp files
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: Trying to remove temp files if they exist."
if [ -f /Library/BCGS/LanSchool/classesbyteachertemp.csv ]
then
    rm /Library/BCGS/LanSchool/classesbyteachertemp.csv
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Removed /Library/BCGS/LanSchool/classesbyteachertemp.csv."
fi
if [ -f /Library/BCGS/LanSchool/studentforclasstemp.csv ]
then
    rm /Library/BCGS/LanSchool/studentforclasstemp.csv
    echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:  - Removed /Library/BCGS/LanSchool/studentforclasstemp.csv."
fi

echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:   "
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: --- Finished $scriptname"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]: ------------------------------------------------------"
echo "`date +"%a %b %d %X"` `hostname` jamf[script-$scriptname]:   "

exit 0