user507220
user507220

Reputation:

using result of a python script to invoke shutdown in terminal(ubuntu)

I've wrote a python script to check whether a condition has been fulfilled(in this case, the condition is a tweet).

Now, I want the computer to shutdown if the condition has been fulfilled. How do I use the result Python provides to invoke a shutdown command in Ubuntu?

Upvotes: 1

Views: 1013

Answers (3)

James Bedford
James Bedford

Reputation: 28982

You can write a simple bash script that checks the result of your python program, and uses the terminal command "shutdown -h now".

Upvotes: 0

user2665694
user2665694

Reputation:

os.system('shutdown -h now')

?

Upvotes: 2

Mike Lewis
Mike Lewis

Reputation: 64177

import os

if condition:
  os.system("shutdown -h now")

Just make sure the user running the script has privileges to call shutdown.

Upvotes: 0

Related Questions