0

I am writing a program that I need to check if user is root (if it is not allow user to input password to get sudo) either way the program will continue but will have less features if it's not root. I tried Change to sudo user within a python script

spawn sudo
expect {
    "Password:" {
        send "password"
    }
}

my python script

import os
import subprocess
if os.geteuid() != 0:
    #function to allow user to change to sudo
    subprocess.call(['tclsh', 'sudo.tcl'])

I got the following error invalid command name "spawn" while executing "spawn sudo" (file "sudo.tcl" line 1)

My question is how to allow user to gain root within the script?

stackover
  • 35
  • 3
  • Did you try the other answer in the linked question? https://stackoverflow.com/a/9527553/6486738 – Ted Klein Bergman Mar 15 '20 at 11:06
  • @TedKleinBergman it works but this allows to try 3 times, I only want one time try – stackover Mar 15 '20 at 11:11
  • Do you mean that you only want the user to be able to try the password 3 times? In that case, you have a different question than the one you posted. I'd suggest you edit in all the requirements into the question. – Ted Klein Bergman Mar 15 '20 at 12:18

0 Answers0