gharris999;477312 Wrote: 
> What I haven't figured out here is how to catch the "boo-boo".
I think sudo's '-S' option may come to the rescue. I tried to replicate
the functionality of this part of the instructions: "sudo -u
squeezeboxserver sudo /sbin/shutdown -k -h now" with this: "sudo
testsudo.sh"

Code:
--------------------
    #!/bin/bash
  USER="squeezeboxserver"
  HOST=`hostname -s`
  
  if [ "$EUID" -ne 0 ]; then
  echo "Please run this command as 'sudo $0'. Exit"
  exit 0
  fi
  
  /usr/bin/wall <<END;
  ** Testing ${USER}'s ability to run privileged commands on $HOST **
  
  You may now see a message announcing immediate shutdown.
  This is only a test. Host $HOST WILL NOT really shutdown.
  END
  sleep 5;
  # reset timestamp
  sudo -k;
  # send a wrong passwd from stdin if asked for it => OK = 0
  echo "" | sudo -S -u $USER sudo -S /sbin/shutdown -k now > /dev/null 2>&1 && 
OK=1 || OK=0;
  
  if [ "$OK" -eq 1 ]; then
  echo -e "\nSuccess!\n";
  else
  echo -e "\nThere was a boo-boo.\n";
  fi
--------------------

Seems to work for me (debian, OS X) Is it useful to you ?

NB: I switched to using bash only because I had trouble with "echo -e"
on OSX using sh. Remove the -e and sh will do nicely.


-- 
epoch1970
------------------------------------------------------------------------
epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711
View this thread: http://forums.slimdevices.com/showthread.php?t=48521

_______________________________________________
plugins mailing list
plugins@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to