Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Script]Find Processes that have updated but not restarted
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Casshan
n00b
n00b


Joined: 07 May 2004
Posts: 53

PostPosted: Wed Aug 05, 2009 10:35 am    Post subject: [Script]Find Processes that have updated but not restarted Reply with quote

I wrote a quick perl script that I'm using with zabbix to check my servers to see if I have a services that has been updated (usually for security reasons), but never got restarted. This must be run as root (or sudo). Just I thought I would post if here for some thoughts or if someones sees something wrong with it, or the way I'm doing it.

Code:

#!/usr/bin/perl


$pids = 0;
open(DELETED_PS, "ls -l /proc/[0-9]*/exe 2>/dev/null|grep deleted|");
while ($line = <DELETED_PS>)
{
        $line =~ /proc\/([0-9]+?)\/exe/;
        $pid = $1;
        chomp($pid);
        print "$pid ";
        if ($ARGV[0])
        {
                $command = `ps -o args p $pid| grep -v COMMAND`;
                chomp($command);
                print "\nCommand: $command \n";
                $command =~ /^(\S*)\s*/;
                $filename = $1;
                print "Program: $filename\n";
                $program = `equery b $filename|grep -v 'Searching for file'`;
                chomp($program);
                print "Ebuild: $program \n";
        }
        $pids++;
}

if ($pids == 0)
{
        print "NONE";
}
Back to top
View user's profile Send private message
Bircoph
Developer
Developer


Joined: 27 Jun 2008
Posts: 261
Location: Moscow

PostPosted: Thu Aug 13, 2009 7:39 am    Post subject: Reply with quote

Seems ok, but I'm just happy with the following:
Code:

find -O3 /proc -type d -regextype posix-egrep -regex "/proc/[[:digit:]]+" \
-exec readlink '{}'/exe \; | gawk '{ if ($NF=="(deleted)") print $0}'

_________________
Per aspera ad astra!
Back to top
View user's profile Send private message
Bircoph
Developer
Developer


Joined: 27 Jun 2008
Posts: 261
Location: Moscow

PostPosted: Thu Aug 13, 2009 4:28 pm    Post subject: Reply with quote

However, there is one problem with this approach: if application use some *.so (or other external data) and that library was updated, application still will old copy in memory.

This behavior may lead to very bad consequences if security update to this kind of library was made. So you should carefully investigate what you're updating, at least on servers.
_________________
Per aspera ad astra!
Back to top
View user's profile Send private message
Casshan
n00b
n00b


Joined: 07 May 2004
Posts: 53

PostPosted: Fri Aug 14, 2009 9:59 am    Post subject: Reply with quote

Is there a way to check for that in memory library version?
Back to top
View user's profile Send private message
boerKrelis
Apprentice
Apprentice


Joined: 01 Jul 2003
Posts: 241
Location: The Netherlands

PostPosted: Sat Sep 05, 2009 11:16 am    Post subject: Reply with quote

Try app-admin/checkrestart .
Back to top
View user's profile Send private message
Bircoph
Developer
Developer


Joined: 27 Jun 2008
Posts: 261
Location: Moscow

PostPosted: Tue Sep 22, 2009 2:06 pm    Post subject: Reply with quote

boerKrelis wrote:
Try app-admin/checkrestart .

Thanks, it works ok for me.
_________________
Per aspera ad astra!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum