Power OFF the Beaglebone Black without Button or hardware intervention

1.5k Views Asked by At

I need to power OFF the Beaglebone black from a Python Code directly without using any gpio buttons or any hardware intervention.

There is the command line shutdown -h now but this command won't work on a python code since it requires a sudo password .... Any idea how can i interract with beaglebone black system ( linux command line without sudo ) in order to power off the board please ?

Thank you .

2

There are 2 best solutions below

0
On BEST ANSWER

Well i tried this solution and it's working:

 from subprocess import Popen, PIPE

 sudo_password = 'temppwd'
 command = 'shutdown -h now'.split()

 p = Popen(['sudo', '-S'] + command, stdin=PIPE, stderr=PIPE,
              universal_newlines=True)
sudo_prompt = p.communicate(sudo_password + '\n')[1]
0
On

Sorry to pop into this old question but it was kind of hurting my eyes :-) While 'sudo' is the proper way to allow program execution as root to users without giving away root's password, it is a really bad practice including the password for a user in a script in plain text and even more for a 'sudoer'.

Although it also has some risks, you may find using the flag SUID may be a more secure approach, as long as the script is secured to be used only for those allowed to do so.

In case you don't know about SUID, here you can find some explanations, although Internet is plagued of examples.

https://www.howtoforge.com/linux_setting_suid_sgid_bits