Created
August 16, 2012 07:37
-
-
Save kofemann/3368116 to your computer and use it in GitHub Desktop.
execute command as a defiend user with X forwarding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# execute command as a defiend user with X forwarding | |
# Example: | |
# xsu auser gedit /some/text/file | |
# | |
if [ $# -lt 2 ] | |
then | |
echo "Usage: xsu <user> <command> [args....]" | |
exit 1 | |
fi | |
NEW_USER=$1 | |
# drop firs argument | |
shift | |
AUTH_FILE=/tmp/xauthexport.$$ | |
xauth list | cut -d ' ' -f1 | xargs -r xauth extract ${AUTH_FILE} | |
chown ${NEW_USER} ${AUTH_FILE} | |
su ${NEW_USER} -c "xauth -i merge ${AUTH_FILE}; $*" | |
rm ${AUTH_FILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment