Script Help

msardes
New Contributor III

trying to modify the FireFox prefs.js file in the local profile with the script below and getting the error below when run from casper. It works fine in terminal.

#!/bin/bash

user=ls -la /dev/console | cut -d " " -f 4

echo user_pref ('"network.negotiate-auth.trusted-uris", "my domain"')';' >>Users/$user/Library/Application Support/Firefox/Profiles/*.default/prefs.js

done

exit 0

Running script modify firefox whitelist.sh...
Script exit code: 2
Script result: /Library/Application Support/JAMF/tmp/modify firefox whitelist.sh: line 5: Users/sardesm/Library/Application Support/Firefox/Profiles/*.default/prefs.js: No such file or directory
/Library/Application Support/JAMF/tmp/modify firefox whitelist.sh: line 7: syntax error near unexpected token `done'
/Library/Application Support/JAMF/tmp/modify firefox whitelist.sh: line 7: `done'
Finished.

Any help would be appreciated.

7 REPLIES 7

JRM
Contributor

I'm not 100% sure but it looks like you may need a / in front of Users just after the redirect.

>>/Users

nessts
Valued Contributor II

+1 /Users will help a lot.
when you have been testing you likely have been at / when running the script, probably its current directory during execution through Casper is likely /var/root and there is no Users directory in there.

milesleacy
Valued Contributor

Hey there,

I think the other responders have caught the error, and assuming that your home folders all live in /Users/, you're done.

If this works and does what you need it to do, don't mess with success. However I do have a suggestion that might be useful...

This script hardcodes the /Users/ path, and that works, but only if all of your user home folders live there. If you have a hidden user or a user with a network home, you'll run into problems.

I would suggest defining the logged in user's username, possibly using the $3 Casper Suite script parameter, then query for that account's home folder path using dscl.

Does that make sense?

nessts
Valued Contributor II

yeah @cOnOr posted a nice way to do that last week and how to get the consoleuser apart from $3 i would search for that.

mm2270
Legendary Contributor III

Agreed with the above. Although in most cases you won't ever see a problem, as soon as this runs against an account that isn't in /Users/ its all over. Always a good idea to get the home directory path, just to be sure.

#!/bin/bash

# When logged in as myself
user=$(ls -l /dev/console | awk '{print $3}'); echo "$user"
mike
userHome=$(dscl . read /Users/$user NFSHomeDirectory | awk '{print $NF}'); echo "$userHome"
/Users/mike 

# When logged in as hidden administrator
user=$(ls -l /dev/console | awk '{print $3}'); echo "$user"
administrator
userHome=$(dscl . read /Users/$user NFSHomeDirectory | awk '{print $NF}'); echo "$userHome"
/var/administrator

msardes
New Contributor III

I will test tomorrow and let you guys know, thanks for the assist. I was thinking it was the * wildcard messing it up.

msardes
New Contributor III

Actually just modded the script and tested and it worked. Thanks for your help. Next time I know silly Mistake.