-2

I'm making a program so that if the user enters a password in a python program incorrectly,it shuts down ubuntu. Example:

>password=input()
    >>if password=="ThePassword":
        >>>print ("Welcome")
    >>>>else:
        >>>>>(shutdown code here)

So if anyone can point me in the right direction, I would be very grateful.

By the way, I'm using Python 3.3 and running Ubuntu 13.10 64 bit

  • did you use google or tried something by yourself? –  Jan 11 '14 at 19:16
  • the command you're looking for is 'sudo shutdown now'. However, since shutdown requires sudo privileges, your python program needs to be run as root (which is something to avoid in any serious application). – Reck Jan 11 '14 at 19:22

1 Answers1

1

What you want is to execute the shell command sudo shutdown -h now.

import subprocess
>password=input()
    >>if password=="ThePassword":
        >>>print ("Welcome")
    >>>>else:
        >>>>>subprocess.call(["sudo", "shutdown", "-h", "now"])

Most likely you will be prompted to enter your administrator password for this to work. You will need to run the program in sudo mode with root permissions.

Bobby
  • 744
  • 9
  • 12