Posted on 04-26-2012 07:54 AM
Hi, I am new to Casper and am having a problem running a shell script from Casper. The script works when run manually or when run from a JSS policy, but when run from Casper, it does not error out, but does not accomplish anything either. Below is the script. Any help would be much appreciated.
find $HOME -type f -name "prefs.js" -exec rm -f {} ;
Posted on 04-26-2012 08:10 AM
When you run scripts in Casper, they generally happen in the context of the admin account, not the logged in user. Depending on how you're running it, $HOME is likely resolving to your admin account, not the logged in account.
The Generally Accepted™ way of doing it is to run it with a policy that has a login or logout trigger and use $3 instead. The jamf binary will resolve $3 to the logging in or out user.
If it's not run at login (or logout) and is instead run at the every15 trigger you can use something like
user=`ls -la /dev/console | cut -d " " -f 4`
and then call something like /Users/$user in your script.
Posted on 10-23-2012 08:29 AM
so how would i use $3 to have a script run as the logged in user? All the script is doing is calling another script as the user and its being run as the admin since its being called by casper:
"sh /location/location/loginscript.sh&"
exit 0
Posted on 10-23-2012 08:33 AM
create a launch agent it will run as the user when he/she logs in.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.my.login</string>
<key>ProgramArguments</key>
<array>
<string>/path/toyour/loginscript.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
permissions should to be 644, file has to be owned by root:wheel lives in /Library/LaunchAgents
Posted on 10-23-2012 10:18 AM
THanks but even though the plist file loads, the script never ends up running, any help would be appreciated