I have to execute few commands in linux but I need to be a super user before I execute the command. This has to be done via python script The scenario is i should execute the following command in the order
>> su
This prompts for password
After entering the password I will have to execute the bluez commands
>> hciconfig hci0 up
>> hcitool lescan
>> hcitool lecc <address>
i need to do this in python but could you please tell me how to be a super user and give password via python then later execute the above commands in order? Meaning,I want to automate the whole process that is execute all the commands without manual intervention.
subprocessmodule for running commands. Instead of usingsu, I recommend running each command withsudo. The user should only be prompted for a password the first time.man sudoers, assuming your Python script can resides in a standard location and a given group of users needs to use it, you can "whitelist" the commands that require super user privileges inside thesudoersfile and useNOPASSWD, so such a script could even be run unattended.