Admin privileges check

I've been tasked to check whether the user of a script has administrative privileges (as they are needed to run certain parts of the script), and if not notify the user to run the script with admin privileges.

Since the script is to be widely distributed, controlling the file rights will not be sufficient.

Any ideas on how to script this check?

Note: I have a couple ideas, but I don't want this to be a hack.

Hard-coding a particular check which is not relevant for the privileges actually required for the script to work sounds like an annoying feature. Can you check for ability to manipulate those resources which the script will actually need to manipulate? Then it's easier to plonk in to alternate access control systems.

I like the way you think... but these are customer requirements against a script that cannot be subjected to various changes...

I was going to perform a check on a task only admin can do, then return the message if it fails.

However, I was looking for a more direct means.

You said you didn't want ad-hockery but here goes anyway. I usually just check for write access to the root directory in my own little admin scripts.

Excellent! Thanks!

If it's not too much to ask, can you post how you do it? Otherwise, I'll work it out.

Thanks again.

test -w /

Dang, have to add length to get to post this reply (-:

Does the trick ( with a bang ) :slight_smile: