Guest User

Untitled

a guest
Oct 2nd, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -lt 2 ]; then
  4. echo "Please specify the user and command to be run."
  5. exit -1
  6. fi
  7.  
  8. USER=$1
  9. shift
  10. ARGS=$*
  11.  
  12. TTY=`/usr/bin/tty`
  13. echo "$TTY" >/tmp/sudoTty_$USER_$EUID
  14.  
  15. cd / # be sure to get out of root's home folder
  16.  
  17. if [ "$TTY" == "/dev/console" ]; then
  18. su -l $USER -c "$ARGS"
  19. elif [ "$TTY" == "" ]; then
  20. su -l $USER -c "$ARGS"
  21. elif [ "$TTY" == "/dev/null" ]; then
  22. su -l $USER- c "$ARGS"
  23. elif [ "$TTY" == "/dev/tty1" ]; then
  24. su -l $USER -c "$ARGS"
  25. elif [ -x /usr/bin/sudo ]; then
  26. /usr/bin/sudo -E -u $USER -n $ARGS
  27. elif [ -x /sbin/runuser ]; then
  28. /sbin/runuser -l $USER -c "$ARGS"
  29. else
  30. echo "Unable to run securely, will try plain ol' su ..."
  31. su -l $USER -c "$ARGS"
  32. fi
Advertisement
Add Comment
Please, Sign In to add comment