Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -lt 2 ]; then
- echo "Please specify the user and command to be run."
- exit -1
- fi
- USER=$1
- shift
- ARGS=$*
- TTY=`/usr/bin/tty`
- echo "$TTY" >/tmp/sudoTty_$USER_$EUID
- cd / # be sure to get out of root's home folder
- if [ "$TTY" == "/dev/console" ]; then
- su -l $USER -c "$ARGS"
- elif [ "$TTY" == "" ]; then
- su -l $USER -c "$ARGS"
- elif [ "$TTY" == "/dev/null" ]; then
- su -l $USER- c "$ARGS"
- elif [ "$TTY" == "/dev/tty1" ]; then
- su -l $USER -c "$ARGS"
- elif [ -x /usr/bin/sudo ]; then
- /usr/bin/sudo -E -u $USER -n $ARGS
- elif [ -x /sbin/runuser ]; then
- /sbin/runuser -l $USER -c "$ARGS"
- else
- echo "Unable to run securely, will try plain ol' su ..."
- su -l $USER -c "$ARGS"
- fi
Advertisement
Add Comment
Please, Sign In to add comment