I have a policy with a bunch of maintenance & system tweak scripts that sometimes takes forever to run. In trying to troubleshoot it, I thought I'd add a couple of lines to the end of each script for additional logging. Does anyone know if / how I can create a parameter that will return the name of the script?
That would allow me to do something like:
MYDATE=$(date '+%a %b %d %H:%M:%S');
echo $MYDATE $2 "Finished running " $[magic-parameter-for-script-name] >> /var/log/jamf.log;
is this doable?
I think something like this should work, though I did not test this when running from a Casper Suite policy. Can't see why it wouldn't actually work in that case as well though.
#!/bin/sh nameOfScript="$(basename "$0")" echo "The script that is running is called: $nameOfScript"
Example. I saved the script to my Desktop, named "my great script.sh" (yes, with the spaces)
The output I get from running it in Terminal is:
The script that is running is called: my great script.sh