0

Please note, I'm NOT asking about the user running it but rather did he run it as sudo command or not

I have a python script, which I want to obligate the user to run it like this:

sudo python3 script.py

and not like this:

python3 script.py

How can I do verify in run time if it was run correctly or not (if so end program using sys.exit())?

daniel
  • 3
  • 6
  • 1
    Your question seems to missing something after “like this:”. – quassy Jan 11 '22 at 15:54
  • 2
    Does this answer your question? [What is the best way for checking if the user of a script has root-like privileges?](https://stackoverflow.com/questions/2806897/what-is-the-best-way-for-checking-if-the-user-of-a-script-has-root-like-privileg) – Brian61354270 Jan 11 '22 at 15:56
  • @quassy thanks :) – daniel Jan 11 '22 at 16:10
  • @Brian not exactly, I'm not asking about the user running it but rather did he run it as sudo or not – daniel Jan 11 '22 at 16:11
  • @daniel `sudo` works by changing the effective user. If you just want to check if the user has `sudo`-level permissions and not some more specific subset, checking the user is the defacto way. See also [Does `sudo` work in terms of changing the effective user and group IDs of a process?](https://unix.stackexchange.com/q/333236) and [How do the internals of sudo work?](https://unix.stackexchange.com/q/80344) – Brian61354270 Jan 11 '22 at 16:15

1 Answers1

0

Check out this topic: What is the best way for checking if the user of a script has root-like privileges?

It has a bunch of solutions that you might find helpful.

ratchek
  • 166
  • 1
  • 8
  • Please Note, I'm not asking about the user running it but rather did he run it as sudo or not – daniel Jan 11 '22 at 16:11