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

Aaron Spangler as at
Thu Mar 18 07:11:31 EST 2004

How about something like this?


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

sudo realcommand1
sudo realcommand2
sudo realcommand3
sudo realcommand4


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

> 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>
> For list information, options, or to unsubscribe, visit:

More information about the sudo-users mailing list