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"')
s=x.readline()
x.close()
if s.find("grep") == -1 :
running=True
print "updating manager is working..."
while(running):
x = os.popen('ps -ef | grep "/usr/bin/gksu --desktop /usr/share/applications/update-manager.desktop"')
s=x.readline()
x.close()
time.sleep(10)
print "still working..."
if s.find("grep") != -1 :
running=False
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
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"')
s=x.readline()
x.close()
if s.find("grep") == -1 :
running=True
print "updating manager is working..."
while(running):
x = os.popen('ps -ef | grep "/usr/bin/gksu --desktop /usr/share/applications/update-manager.desktop"')
s=x.readline()
x.close()
time.sleep(10)
print "still working..."
if s.find("grep") != -1 :
running=False
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
9 comments:
well , this is nice :)
is there a reason you chose python or you just wanted to write in python ?
Thanks for sharing this :)
there are three reasons why i have choosen python:
-fun and easy
-learning something new
-installed by default in many linux distros
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
1)no
1)no
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...
Hi,
Just a small correction
The last line indentation should be along the while statement .....
Thanks for the script though !
link:http://surajitray.com
# apt-get -y --fix-broken update ; apt-get dist-upgrade ; poweroff
مش عارف إيه اللي فكرني بالبوست ده
:)
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 :)
@Anonymous
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
thanks...
Post a Comment