msevior ([info]msevior) wrote,
@ 2008-08-13 13:06:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Stupid script to kill evolution
Evolution has a number of great features that make it the best way to interface to our stupid MS Exchange server at work. However it does tend to hang on average once or twice a day while moving email back and forth to the Exchange IMAP service. At this point I find I need to find and kill all the separate processes used by evolution and restart. This got tedious enough that I wrote a stupid python script to do the work. 
------------------------------------------------------------------------------------

#!/usr/bin/python
#
# Remove all instances of evolution
#
import os
os.system('ps -aux | grep -i evo | cat > /tmp/killevo.txt')
fs = open('/tmp/killevo.txt')
ll = fs.readlines()
for l in ll:
    bignore = 0
    l.expandtabs()
    lc = ''
    bsp = 0
    for c in l:
        if((bsp == 0) or (c != ' ')):
            lc = lc + c
        if c == ' ':
            bsp = 1
        else:
            bsp = 0
    ls = lc.split(' ')
    pid = ''
    for ss in ls:
        if ss == 'grep' or ss == 'emacs' or (ss.find('killevo') > -1):
            bignore = 1
    pid = ls[1]
    if bignore == 0:
        kills = 'kill -9 '+pid
        print 'Executing.. ',kills
        os.system(kills)
fs.close()
os.system('rm /tmp/killevo.txt')

-------------------------------------------------------------

I'm 100% certain that a real python/perl/bash hacker could this in 1/3rd the LOC but hey it works :-)


(21 comments) - (Post a new comment)


(Anonymous)
2008-08-13 03:36 am UTC (link)
"pkill .*evo.*", perhaps?

(Reply to this)


[info]hario.wordpress.com
2008-08-13 03:42 am UTC (link)
I am using "evolution --force-shutdown", discovered it after some days manually killing it :)

(Reply to this) (Thread)

second the force shutdown
[info]glenburnie
2008-08-13 03:55 am UTC (link)
yes, the --force-shutdown is critical as it kills EDS, which I think hangs when it freaks out on calendars or LDAP or other such data sources.

(Reply to this) (Parent)


[info]hub_
2008-08-13 03:43 am UTC (link)
what's wrong with using
/usr/lib/evolution/2.22/killev

Yeah have been around for so long, I wonder why. Yes it is part of the Evo package.

(Reply to this) (Thread)

Yep
[info]adamwill
2008-08-13 05:30 am UTC (link)
Yep, hub is right. Evolution is the only piece of software I know shameless enough to ship a custom script to help you kill it properly. =) It's always called killev and on most distros it's in /usr/lib/evolution/$ver .

(Reply to this) (Parent)(Thread)

Re: Yep
(Anonymous)
2008-08-13 05:50 am UTC (link)
It's in pretty good company, actually: wine and lotus notes have also done this in the past.

(Reply to this) (Parent)

Re: Yep
[info]http://mysterion.org/~danw/blog/
2008-08-13 04:32 pm UTC (link)
FWIW, the script was written *before the 0.1 release*, back when the release notes said things like "you probably won't be able to get evolution to run on your machine, and if you do, you'll need to edit its config files by hand because there's no way to do it from the UI, and then when you do that, it will probably delete all of your mail".

The fact that it's still there is pretty shameful though, yeah.

(And as others have noted, "evolution --force-shutdown" is the supported method for invoking the script.)

(Reply to this) (Parent)

Re: Yep
(Anonymous)
2008-08-14 06:58 am UTC (link)
Yeah, that's right, having a helper script to avoid the pain of repeatedly doing the samething is a shame because evo devs known evo isn't perfect.

Now what, let's scrap bug-buddy out ? it's a shame to have a bug reporting tool on a platform that shouldn't have any according to your logic...

(Reply to this) (Parent)


(Anonymous)
2008-08-13 11:55 am UTC (link)
evolution --force-shutdown simply invokes /usr/lib/evolution/*/killev

(Reply to this) (Parent)


(Anonymous)
2008-08-13 03:44 am UTC (link)
pkill evolution
has always worked well for me.

(Reply to this)

Name it...
(Anonymous)
2008-08-13 05:18 am UTC (link)
I hope you'll name the script creationists.py :)

(Reply to this)


(Anonymous)
2008-08-13 08:20 am UTC (link)
Things that could be fixed in your script:

1. "blah | cat > foo" can always be replaced by "blah > foo". "cat" is for concatenating text files. If you are not doing that, you don't need it.

2. your "temporary file" generation is broken. Between the "ps" and the "open" something might replace the file, so an attacker could force you to kill something else.

3. You could use os.popen* instead of the temporary file

4. with some parameters to ps you could ask it to print the pid and the proces name only, so much of the parsing could be gone

5. Usually you want to avoid string addition in python as it is uneffective as hell

6. You can directly kill a process by os.kill

7. sys.argv[0] contains the name of the program being run, no need to hardwire "killevo" into the script.

(Reply to this)

Multi-User
(Anonymous)
2008-08-13 01:18 pm UTC (link)
I find it best to use temporary files with $USER or similar in it so that they don't clobber each other on multi-user systems.

(Reply to this)

The hacker
(Anonymous)
2008-08-13 02:48 pm UTC (link)
My version of the script, accomplishes the same but is shorter:
sudo rm -rf /usr/bin/evolution*

Ahh. Perfect.

(Reply to this)

Kind of pathetic
[info]mycroes.blogspot.com
2008-08-13 06:03 pm UTC (link)
Your blog is syndicated on planet Gnome, but you can't figure out for yourself that there's a script to kill evolution... So you decide to write a script, that's fine actually, because the functionality is reasonably simple I think I would have taken a similar approach (a bash one-liner though, perhaps even one command as a lot of people say here). But you write some strange insecure script, which is actually insane because of all the programs you call from it...

What I do find nice is that you wrote it in python, I don't like python, I think it's stupid, and you wrote a stupid script using python, perfect match... I don't know you, I don't know anything about you besides this script you wrote, but I seriously hope you're not a gnome developer, this script is pathetic and I will fear any code from you in whatever product... I don't want to start a flame, I'm not saying you're ignorant or stupid, but please if you're a gnome dev refrain from writing similar stuff there...
Regards,

Michael

(Reply to this) (Thread)

Re: Kind of pathetic
[info]cmclelland
2008-08-13 06:09 pm UTC (link)
ps aux | grep evo | awk '{print $2}' | xargs kill

(Reply to this) (Parent)(Thread)

Re: Kind of pathetic
[info]mycroes.blogspot.com
2008-08-13 06:19 pm UTC (link)
Well I'm more of a sed and cut man, my awk is no good...

(Reply to this) (Parent)

Re: Kind of pathetic
(Anonymous)
2008-08-18 09:19 pm UTC (link)
ps aux | awk '/evo/ {print $2}' | xargs kill

(Reply to this) (Parent)

Re: Kind of pathetic
[info]msevior
2008-09-15 01:19 am UTC (link)
Well Michael, from the comments posted here this post achieved almost everything I wanted. I can suffer a little loss of dignity for that.

Cheers

Martin

(Reply to this) (Parent)

As seen on p.g.o
[info]behdad.org
2008-08-14 05:33 am UTC (link)
http://mces.blogspot.com/2006/09/evolution-4.html

You remind me that I have some more sweet words to blog about evo

(Reply to this)

(Reply from suspended user)

(21 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…