On 2014-04-30 20:02, ToddAndMargo wrote: > On 04/30/2014 10:38 AM, Jeffrey Anderson wrote: >> It seems to me that having a shell script prompt for the root password >> is a recipe for disaster, but you can easily check to see if the user is >> already root, and bail if not. >> > > That is what I currently do. I am just wanting to get fancy: > > if [ -z "`/usr/bin/whoami | grep root`" ]; then > echo "" > # ErrorSound > echo 'Dude! You must be root to do this.' > echo "Try" > echo " su root -c \"updateffth $1\"" > echo 'Exiting. Bummer ...' > echo "" > Pause > exit 1 > fi >
sudo has the charm to create log entries, and can be easily automated. What I miss in your example is a syslog call that someone unauthorized tried to execute the script. Also I would replace pause with `sleep $num' or `read -t $num DUMMY' so in case the script is executed by cron it doesn't wait for a signal.