Kalebu Jordan

Become a Pro Python Developer

Hi guys,

One thing that as a python programmer you should be proud of is that it gives you the capability to automate a bunch of repetitive tasks effortlessly just with the basics.

In this article, you’re going to learn about building a cross-platform python program for automating shutdown.


In this article, we gonna use OS + Platform to implement our script, both of them comes with the python standard library utilities so you don’t need to install anything

Basics of Platform Module

Platform Module, we will use it to determine the type of Operating system in which our program is running.

Example of usage

>>> import platform
>>> platform.system()

If you’re using windows you should see Windows instead of Linux.

Basics of OS Module

OS Module , we are going to use this module to run terminal/command prompt command in Python.

To run run the system command in Python we are going to use system ( )

Example of Usage

>>> import os
>>> os.system('echo hello')

The command for shutdown computer varies depending on the operating system .

System command for automated shutdown

Below a system command for automating computer shutdown, our task gonna lie on running programmatically do this based on user input from python.

shutdown command for Linux

shutdown -t time_in_minutes
kalebu@kalebu-PC:~$ shutdown -t 12
Shutdown scheduled for Wed 2020-06-03 15:55:40 EAT, use 'shutdown -c' to cancel.
cancelling automated shutdown
kalebu@kalebu-PC:~$  shutdown -c 

shutdown command for Window

shutdown -s -t time_in_seconds
shutdown -s -t 1200
Cancelling scheduled shutdown in Window
shutdown -s -t a

Building our Python program.

Therefore we need to get the time parameter to automate the shutdown from the user and then run those command from our Python program.


import os
import platform

OS_type = platform.system()
OS_type = OS_type.lower()

def shutdown(time):
    It automate shutdown by scheduling the 
    time for computer to shutdown

    if OS_type == 'linux':
        shutdown_str = 'shutdown -t '+ str(time)
    elif OS_type == 'windows':
        time = time * 60
        shutdown_str == 'shutdown -s -t ' + str(time)
        print('Sorry this feature is not available in ', OS_type)


def cancel_shutdown():
    if OS_type == 'linux':
        cancel_str = 'shutdown -c'
    elif OS_type == 'windows':
        cancel_str = 'shutdown -a'

def main():
    print('Use Shutup To schedule your shutdown'.center(50, '='))
    print('1.Automate Shutdown\n2.Cancel shutdown')
    option = int(input('Option here: '))
    if option == 1:
        time = int(input('\nEnter time to shutdown in Minutes : '))
    elif option == 2:
        print('Shutdown successful canceled ...')
        print('Invalid option try again!!!\n')

if __name__ == '__main__':

Output :

I recommend you to also check these, based on your interest;

Hope you find this post interesting , don’t forget to subscribe to get more tutorials like this. Full code available on My Github

In case of any suggestion or comment , drop it on the comment box and I will reply to you immediately.

Leave a Reply


Enjoy this blog? Please spread the word :)