16 May Efficiently Transfer Files to an OS X Device with SDClient
Have you ever needed to copy a file from a share to a more than one Mac in your environment? My guess is the answer to that is yes, I know it was for the potential customer I spoke with on the phone today. Whether you’re trying to apply a configuration file for a package, settings for a proxy server, VPN configuration files or any of the myriad of other reasons, what you’re transferring isn’t the important question, it’s how do you do it.
Luckily sdclient, the tool that is the brains behind all things software distribution for the Mac, has a bunch of goodness via command line switches that can be used to download files and place them into specific locations; all the while still taking advantage of the download technologies built into the agent.
To leverage sdclient, we’ll write a shell script that will tell sdclient what file to download and where to place it. The entire script is very short. There will be two variables, one for the source file location and the second for the destination location.
The only thing you need to really pay attention to in regards to the source location is to ensure the file is accessible via http. You can setup a variable or just supply the location. I like to create a variable so that the code can be better documented and easier to read for others. Here is my source variable.
We’ll repeat the process for the destination location.
In addition to the destination variable, the script will include a quick check to ensure the destination folder exists on the end node and if not, create it.
if [ ! -d "$destinationLocation" ]; then echo "Location doesn't exist. Creating directory" mkdir $destinationLocation echo "$destinationLocation created" fi
The actual download and placement of the file will be done by sdclient with three switches: -noinstall, -package and –destdir. The switch names are pretty self-explanatory, the –noinstall tells sdclient to not execute the file that will be downloaded. The –package switch is where you insert the path to the source file available, again available on the http share. Lastly, the –destdir switch tells sdclient where to place the file on the Mac client.
All done, your command sdclient command should look something like:
/Library/Application\ Support/LANDesk/bin/sdclient -noinstall -package "$fileToCopy" -destdir "$destinationLocation"
Here is the entire example script.
#!/bin/sh # FileTransfer.sh # Created by Bennett Norton on 5/16/16. # This script will copy a file from the source destination and place it on the Mac into the destination folder # Change the path variables #File to copy #change this to match your hosted path, it needs to be http fileToCopy="http://ldserver.ldlab.org/SoftwareDist/MacPackages/ExampleFile.txt" #Location to copy file to #change this to match your destination path destinationLocation="/Path/To/Your/Destination/Folder " #Check to see if destination exists and if not, create it if [ ! -d "$destinationLocation" ]; then echo "Location doesn't exist. Creating directory" mkdir $destinationLocation echo "$destinationLocation created" fi #Download and execute command #You shouldn't need to make any changes here #-noinstall ensure the package does not get executed #-package is the source url path #-destdir is the destination url path /Library/Application\ Support/LANDesk/bin/sdclient -noinstall -package "$fileToCopy" -destdir "$destinationLocation"
As discussed in previous posts, save this file as a .sh file and set the execute permission on it by running the command below.
sudo chmod +x /path/to/script.sh
Once you’ve set the execute permissions, copy the script to your package repository and create a LANDESK Software Distribution package to deploy.
Creating LANDESK Management Suite Mac Packages
- Open the LANDESK Console
- Navigate to the top menu bar, select Tools > Distribution > Distribution Packages.
- In the lower left menu tree, highlight My Packages or Public Packages from within the Distribution Packages window
- On the Distribution menu bar, press the New Package button and select New Macintosh Package.
- Give the package a name
- Provide a description as well as any metadata information desired
- Set the primary file to the script file you previously transferred to your package share
- Fill out the Metadata details if desired, specifically supplying a logo so it shows up properly in the portal
- Save the package
Creating a Scheduled Mac Software Distribution Task
- Right click on the Mac software distribution package created and select Create Scheduled Task
- From the network view, select and drag the desired machine(s), user(s) or query(ies) and drop them onto the task
- Now, right click on the task and select properties
- Set the desired Task type under Task Settings as to whether you want a push, a policy or a hybrid of the two types in a policy-supported push
- Set the radio button in the Portal Settings to either Recommended or Optional if you desire to put the package into Workspaces. If you’d like to automatically deploy the app, select Run automatically
- Change the Reboot Settings or Distribution and Patch settings if desired
- Set the schedule task settings with the appropriate start time