I'm new to Casper and new to scripting. I'm looking to apply a few dock items using dockutil at login once per user per machine. I am able to get the following script to run successfully via policy with a manual trigger...
#!/bin/sh
###
# Script to add and remove items from dock using dockutil.
###
sleep 10
# Remove Mail
/usr/bin/sudo /usr/local/bin/dockutil --remove 'Mail' --no-restart --allhomes
# Add OIT IP Helper
/usr/bin/sudo /usr/local/bin/dockutil --add /Applications/OIT IP Helper.app --position beginning --no-restart --allhomes
# Add Self Service
/usr/bin/sudo /usr/local/bin/dockutil --add /Applications/Self Service.app --after 'OIT IP Helper' --no-restart --allhomes
# Relaunch Dock
/usr/bin/sudo killall Dock
exit 0
When I run the same script with a login trigger it does not work, but it runs. I understand this could be due to login policy wanting to run as the service account for JSS but when I attempt to run it as a user I run the following and it fails both at login or with manual trigger.
#!/bin/sh
###
# Script to add and remove items from dock using dockutil.
###
sleep 10
User=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'
# Remove Mail
/usr/bin/sudo -u $User /usr/local/bin/dockutil --remove 'Mail' --no-restart --allhomes
# Add OIT IP Helper
/usr/bin/sudo -u $User /usr/local/bin/dockutil --add /Applications/OIT IP Helper.app --position beginning --no-restart --allhomes
# Add Self Service
/usr/bin/sudo -u $User /usr/local/bin/dockutil --add /Applications/Self Service.app --after 'OIT IP Helper' --no-restart --allhomes
# Relaunch Dock
/usr/bin/sudo killall Dock
exit 0
If anyone could tell me where I'm going wrong or can offer some help I'd appreciate it.