
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-18-2019 12:51 AM
I'm running the following script by hand in Terminal which works successfully to mount our user's homedrive:
filteredLDAP=$(ldapsearch -LLL -x -h our.domain -b "OU=People,DC=mds,DC=ad,DC=dur,DC=ac,DC=uk" "(sAMAccountName=$USER)" homeDirectory | sed 's/[^:]*: //;2q;d' | sed 's////g')
connTYPE=$"smb:"
connCONCAT=$"$connTYPE$filteredLDAP"
open $connCONCAT
When I add the script to self-service, nothing happens - I think it's because the script is being run as root and not the current user. Is that the case, and if so, how can I amend to run successfully?
Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-18-2019 02:11 AM
You can run actions as the user with the command below.
sudo -u username - H
Something like this might work.
#!/bin/sh
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
filteredLDAP=$(sudo -u "$loggedInUser" -H ldapsearch -LLL -x -h our.domain -b "OU=People,DC=mds,DC=ad,DC=dur,DC=ac,DC=uk" "(sAMAccountName=$USER)" homeDirectory | sed 's/[^:]*: //;2q;d' | sed 's////g')
connTYPE=$"smb:"
connCONCAT=$"$connTYPE$filteredLDAP"
sudo -u "$loggedInUser" -H open "$connCONCAT"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-18-2019 02:11 AM
You can run actions as the user with the command below.
sudo -u username - H
Something like this might work.
#!/bin/sh
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
filteredLDAP=$(sudo -u "$loggedInUser" -H ldapsearch -LLL -x -h our.domain -b "OU=People,DC=mds,DC=ad,DC=dur,DC=ac,DC=uk" "(sAMAccountName=$USER)" homeDirectory | sed 's/[^:]*: //;2q;d' | sed 's////g')
connTYPE=$"smb:"
connCONCAT=$"$connTYPE$filteredLDAP"
sudo -u "$loggedInUser" -H open "$connCONCAT"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-18-2019 02:23 AM
thanks, this is working now

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-23-2019 09:55 PM
Can you mark it as answered please? @pchrichard
