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?