I forbindelse med dårlig “shared memory” styring på noen av applikasjonene på jobb ser jeg for meg følgene implementering.
1. List ut shared memory segmenter (ipcs -m)
2. List ut påloggede brukere (w)
3. Slett alle shared memory segmenter fra brukere som ikke lenger er pålogget(ipcrm).
[bash]
#!/bin/bash
self=`basename $0`
if [[ "$1" = "-h" || "$1" = "–help" ]]; then
cat <<EOM
$self:
$self list leftover
$self -r list and remove leftover
$self -h or –help this text
EOM
exit 0
fi
if [ "$(id -u)" != "0" ]; then
echo "$self must be run as root"
exit 1
fi
if [ -f /etc/redhat-release ] ; then
if [[ ! `cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//` = "3" ]] ; then
echo "$self only tested on RHEL3"
exit 1
fi
fi
ps -ef | egrep -v "clamav|daemon|root|rpc|smmsp|UID|xfs|gdm|ntp" | awk ‘{print $1}’ | sort -u > /tmp/online_ps
w | egrep -v "root|USER|load average" | awk ‘{print $1}’ | sort -u > /tmp/online_w
cat /tmp/{online_ps,online_w} | sort -u > /tmp/online_
filter=`awk ‘{printf "%s",$0"|"}; END{print "root|gdm|Shared|shmid|Memory|owner|Message|msqid|Semaphore"}’ /tmp/online_`
rm -f /tmp/{online_ps,online_w,online_}
echo "Leftover shared mem"
ipcs -m | egrep -v "$filter"
echo "Leftover message q’s"
ipcs -q | egrep -v "$filter"
echo "Leftover semaphores"
ipcs -s | egrep -v "$filter"
if [[ "$1" = "-r" ]]; then
echo "Removing shared mem"
for i in `ipcs -m | egrep -v "$filter" | awk ‘/./{print $2}’`; do ipcrm -m $i;done
echo "Removing semaphores"
for i in `ipcs -s | egrep -v "$filter" | awk ‘/./{print $2}’`; do ipcrm -s $i;done
echo "Removing message q’s"
for i in `ipcs -q | egrep -v "$filter" | awk ‘/./{print $2}’`; do ipcrm -q $i;done
fi
[/bash]