Ahmed Kotb Main Blog



last two weeks i was busy in my exams and ubuntu wanted to download alot of updates..that is normal but for people with low connection speed having alot of updates is not that nice...as i will have to leave the computer open for a long time and offcourse i will not be able to use the Internet as the update-manager draws all the speed..so i decided to leave it open and go some where but i found no option in ubuntu update manager to close the computer after finishing updates so i created this small python script that will shutdown the computer after finishing all the updates and here it is...

import time
import os
import getpass
password = getpass.getpass('please enter your password : ')
x = os.popen('ps -ef | grep "/usr/bin/gksu --desktop /usr/share/applications/update-manager.desktop"')
if s.find("grep") == -1 :
 print "updating manager is working..."

   x = os.popen('ps -ef | grep "/usr/bin/gksu --desktop /usr/share/applications/update-manager.desktop"')
   print "still working..."
   if s.find("grep") != -1 :
  os.popen("sudo -S shutdown -h 5", 'w').write(password)

Script usage is very simple :
just lunch the update manager and start the update process as usual then open a terminal and lunch the script (python "scriptname.py")
you will have then to write your password it is only used to call the shutdown command (i promise :D ) then you can go to sleep :D and the script will do the rest...
after finishing updates the script will give you 5 min to cancel the shutdown proccess if you have changed your mind...
hope you found this script useful



  1. Amani Salah  

    well , this is nice :)

    is there a reason you chose python or you just wanted to write in python ?

    Thanks for sharing this :)

  2. Ahmed Kotb  

    there are three reasons why i have choosen python:
    -fun and easy
    -learning something new
    -installed by default in many linux distros

  3. aboelnour  

    salam 3alikom
    nice idea
    but 2 questions:
    1)as python is a dynamic oop language
    can i use any language?
    2)can i use the same idea for other OS?
    "Expected" ans:P

  4. Ahmed Kotb  

    answers :D
    1- sure u can use any language but python is the easiest i think...

    2-sure but offcourse you will have to change things in the script...

  5. Anonymous  


    Just a small correction

    The last line indentation should be along the while statement .....

    Thanks for the script though !


  6. aboelnour  

    # apt-get -y --fix-broken update ; apt-get dist-upgrade ; poweroff
    مش عارف إيه اللي فكرني بالبوست ده

  7. Anonymous  

    I runned the script and it tried to shutdown the computer before the update was complete...
    I think
    "os.popen("sudo -S shutdown -h 5", 'w').write(password)"
    should be outside "while(running):"

    btw, nice script :)

  8. Ahmed Kotb  


    glad that you have liked the script , and you are right the last line should be out of the while block , an extra space was added by mistake , i will fix it

Post a Comment

Recent Posts

Recent Comments



The next version of Ubuntu is coming soon


My Stats