I am trying to create a Policy that copies an alias to the Desktop. I used composer to put the file in /Users/Shared and then a bash script that copies it to the desktop use the command "cp -R "/Users/Shared/IBM/IBM i Access" ~/Desktop". The alias is there but it is broken. If I go to /Users/Shared and try it from there it works just fine. It seems like it gets broken in the copy process. What am I doing wrong?
Alias broken when copied to Desktop
Best answer by AJPinto
You need a variable to tell the command where the files need to go. ~/Desktop is the desktop for the currently logged in user, when JAMF is running the script that will be root so the path is being filled as "/users/root/desktop" hence your problems.
If this script will only be run from JAMF itself (not a part of a package or locally run) you can just use jamf parameters, "/users/$3/desktop" and JAMF will sort out the logged in user for you.
$1 = Mount point of the target drive. This is / if you're booted to the
target or /Volumes/targetDrive if you're not booted to it.$2 = the computer name
$3 = the current user's shortname. If no one is logged in, $3 will be empty.
If you want to shove this in a package you will need an array to make the variable. Something like this should work fine, just keep in mind it wont work if no one is logged in.
#!/bin/bash
########################################################################
# Script Name:
# Author:
# Date:
# Enhancements
# Comments:
########################################################################
#*=============================================================================
#*Defining Variables
#*=============================================================================
#----------------------DEFINE LOGGED IN USER----------------------------------#
#Stuff to figure out who is logged in
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
#Echo the logged in user so it will show in the policy logs
echo "User recognized as $loggedInUser"
#----------------------DEFINE LOGGED IN USER END------------------------------#
#function to do the thing
cp -R "/Users/Shared/IBM/IBM i Access" "/Users/$loggedInUser/desktop"
Lastly. JAMF Does not talk about this much, but there is a feature in JAMF called FUT and FEU. These flags are in JAMF Admin and JAMF > Settings > Packages. They both require the package to be a .dmg, and will not work with the .pkg format. The function is when checked JAMF will replace any user specific stuff like a file path, with the current user information on the device it is being run.
When using FEU if the file path you packaged the files in is "/Users/globper/Desktop". When I install the package JAMF will change the path automatically to "/users/AJPinto/Desktop".
If you package the files in a nonuser specific location, FUT nor FEU will work.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
