forked from ossobv/vcutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwcheckrestart
executable file
·73 lines (67 loc) · 2 KB
/
wcheckrestart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
# wcheckrestart (part of ossobv/vcutil) // wdoekes/2014 // Public Domain
#
# Checks which services need to be restarted after an upgrade. Inspired
# by:
# - checkrestart (from debian-goodies), a more complicated version of this
# - https://locallost.net/?p=233
# - http://askubuntu.com/questions/194/how-can-i-install-just-\
# security-updates-from-the-command-line
#
# Usage:
#
# sudo wcheckrestart [-v] [options_to_ps]
# sudo wcheckrestart -vv
#
# Examples:
#
# # Check which processes need a restart and restart them.
# sudo wcheckrestart
# sudo /etc/init.d/this-and-that restart # :)
#
# # Check which PIDs still have an old libssl loaded.
# sudo wcheckrestart -vv | grep libssl
#
# # Pass options 'h' and '-o pid' to 'ps', to get the PIDs only.
# sudo wcheckrestart -v h -o pid # | awk NF=NF RS= OFS=,
#
verbose=0
options_to_ps=f
if test "$*" = "-vv"; then
verbose=2
elif test "$1" = "-v"; then
verbose=1
shift
fi
if test -n "$*"; then
options_to_ps="$@"
fi
if test $(whoami) != root; then
echo "must be root" 2>/dev/null
exit 1
fi
shown=""
toshow=""
for pid in `ps fhax -opid`; do # we need 'f' for the right order
res=$(egrep '\.so(\..*)? \(deleted\)$' /proc/$pid/maps 2>/dev/null)
if test $? -eq 0; then
ppid=$(awk '{print $4}' /proc/$pid/stat)
shown="$shown $pid "
# If not verbose, and parentpid is not 1 (in case we've already shown
# /sbin/init) and we've already shown the parent, then don't show it.
if test $verbose -eq 0 -a $ppid != 1 && echo "$shown" | grep -q " $ppid "; then
continue
fi
toshow="$toshow,$pid"
if test $verbose -ge 2; then
cmdline=$(sed -e 's/\x00/ /g' /proc/$pid/cmdline)
printf "PID $pid $cmdline\n"
echo "$res" | sed -e "s/^/ $pid /"
echo
fi
fi
done
if test $verbose -le 1 -a -n "$toshow"; then
ps $options_to_ps -p $(echo "$toshow" | sed -e 's/^.//')
fi
# vim: set ts=8 sw=4 sts=4 et: