Posted on 12-03-2012 01:04 PM
Ok, maybe a little misleading for the title but I didn't know a better way to name it.
Most of the time I have casper admin open on my Mac, which includes having the volume "CasperShare" mounted on my mac. If a policy happens to run while I have CA open, it will be running from "CasperShare 1." I have several policies that run post-folght scripts that use the jamf utility to install a package, etc, and I need to specify the correct path to the package. Any quick way of telling what mounted volume a script is running from?
Solved! Go to Solution.
Posted on 12-03-2012 01:09 PM
I believe this should do the trick.
DIR=$( cd "$( dirname "$0" )" && pwd )
Posted on 12-03-2012 01:09 PM
I believe this should do the trick.
DIR=$( cd "$( dirname "$0" )" && pwd )
Posted on 12-03-2012 02:12 PM
Yup,
Mr. Blake is on to the right solution here using a positional parameter. $0 is the full path of the script. That is why you will see things like `srm $0` at the end of a postflight script so the script removes itself after running.
Here is a proof of concept I whipped up really fast:
#!/bin/bash
# test to find full path of script
echo "$0 is the full path"
exit 0
Here is the output:
$ bash -x /Users/tlarkin/Documents/scripts/test_pwd.sh
+ echo '/Users/tlarkin/Documents/scripts/test_pwd.sh is the full path'
/Users/tlarkin/Documents/scripts/test_pwd.sh is the full path
+ exit 0
Hope that helps you.
Thanks,
Tom
Posted on 12-06-2012 05:53 PM
Thanks! Your answers set me on the right path. It's amazing what you can think of when you aren't completely losing your mind at work. It's as simple as 'cd ..' since it's a script being run from Casper, i already know it's location - CasperShare/Scripts, so if i just issue a
cd ..
Parent=`pwd`
that gives me the parent directory of the Scripts directory.... and then I just remembered that scripts don't run from the CasperShare unless you call them with the jamf binary. Is there a way to trace the running script back to the share it came from?
Posted on 12-07-2012 05:18 AM
lsof is your friend. While a script is running, something like
lsof /usr/sbin/jamf
Should get you a list of open files that the jamf binary has called. That will give you the full file path and you should see a /Volumes/CasperShare or /Volumes/CasperShare 1 depending on the state of your machine (e.g. if Casper Admin is open)