@Sachin_Parmar I finally had a few minutes today to test this. I made the following minor change and it appeared to work for me:
#!/bin/sh
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
echo $loggedInUser
sudo -u $loggedInUser brew install wget
I think that your install script was actually choking on the single quotes around the brew command. Once I removed the quote I was able to get brew to run and try to install wget for me. You can see the log:
Running script brewTest...
Script exit code: 0
Script result: swood
No entry for terminal type "unknown";
using dumb terminal settings.
Warning: wget-1.17.1 already installed
Hope that helps.