how to confirm non-root user is a qualified sudo user in a (perl)script?

Aaron Spangler as at insight.rr.com
Thu Mar 18 07:11:31 EST 2004


How about something like this?

#!/bin/sh
tmpfile=/tmp/sudo_test$$

sudo touch $tmpfile
if [ -f $tmpfile ];then
  echo "Your sudo privs work fine"
else
  echo "Sorry.  Unable to use sudo"
  exit 2
fi
rm -f $tmpfile

sudo realcommand1
sudo realcommand2
sudo realcommand3
sudo realcommand4

 -Aaron


----- Original Message -----
From: "Ken Wolcott" <ken.wolcott at med.ge.com>
To: "sudo mailing list" <sudo-users at sudo.ws>
Sent: Wednesday, March 17, 2004 2:15 PM
Subject: how to confirm non-root user is a qualified sudo user in a
(perl)script?


> Hi;
>
> I am writing a perl script that needs to be run as a non-root user
> but uses sudo extensively.  How do I verify in the
> script (non-interactively) that the user running the script has
> sudo privileges?  It looks like I need to use expect (*sigh*) to
> get underneath the tty layer.  Right now it looks like I don't have
> any choice but to assume that the user already has sudo
> privileges.  I have looked at the sudo man pages and in the mailing list
> archives but I did not find anything I thought was pertinent to the
> issue I am facing.  The sudo privileges must be absolute like the
> following in the sudoers file:
>
> username ALL = NOPASSWD: ALL
>
> Any hints?
>
> Thanks,
> Ken
>
>
> ____________________________________________________________
> sudo-users mailing list <sudo-users at sudo.ws>
> For list information, options, or to unsubscribe, visit:
> http://www.sudo.ws/mailman/listinfo/sudo-users
>




More information about the sudo-users mailing list