Skip to main content
Question

Running a script in Casper


Forum|alt.badge.img+1

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 {} ;

4 replies

Forum|alt.badge.img+24
  • Valued Contributor
  • 1892 replies
  • April 26, 2012

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.


Forum|alt.badge.img+4
  • Contributor
  • 15 replies
  • October 23, 2012

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


Forum|alt.badge.img+18
  • Valued Contributor
  • 1007 replies
  • October 23, 2012

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


Forum|alt.badge.img+4
  • Contributor
  • 15 replies
  • October 23, 2012

THanks but even though the plist file loads, the script never ends up running, any help would be appreciated


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings