Benjamin Renard commited on 2011-01-17 17:01:17
Showing 1 changed files, with 74 additions and 0 deletions.
... | ... |
@@ -0,0 +1,74 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+SD=$( dirname $0 ) |
|
4 |
+SD=$( pwd $SD ) |
|
5 |
+SRC=$SD/check_mem |
|
6 |
+DD=/usr/local/lib/nagios/plugins |
|
7 |
+DST=$DD/check_mem |
|
8 |
+ |
|
9 |
+NAGIOS_PLUGINS_CFG_DIR=/etc/nagios-plugins/config |
|
10 |
+NAGIOS_PLUGINS_CFG_DST=$NAGIOS_PLUGINS_CFG_DIR/mem.cfg |
|
11 |
+ |
|
12 |
+[ ! -d $DD ] && mkdir -p $DD |
|
13 |
+ |
|
14 |
+DO=1 |
|
15 |
+if [ -e $DST ] |
|
16 |
+then |
|
17 |
+ ASK=1 |
|
18 |
+ if [ -L $DST ] |
|
19 |
+ then |
|
20 |
+ D=`ls -l $DST|awk '{print $11}'` |
|
21 |
+ if [ "$D" = "$SRC" ] |
|
22 |
+ then |
|
23 |
+ echo "Symbolic link $DST already exist. Pass." |
|
24 |
+ ASK=0 |
|
25 |
+ DO=0 |
|
26 |
+ fi |
|
27 |
+ fi |
|
28 |
+ if [ $ASK -eq 1 ] |
|
29 |
+ then |
|
30 |
+ echo "File $DST already exists." |
|
31 |
+ echo -n "Abort (Y,n) ? " |
|
32 |
+ read a |
|
33 |
+ [ "$a" != "N" -a "$a" != "n" ] && exit |
|
34 |
+ echo "Saved old file in $DST.orig" |
|
35 |
+ mv $DST $DST.orig |
|
36 |
+ fi |
|
37 |
+fi |
|
38 |
+ |
|
39 |
+[ $DO -eq 1 ] && ln -s $SRC $DST |
|
40 |
+ |
|
41 |
+[ ! -d $NAGIOS_PLUGINS_CFG_DIR ] && mkdir -p $NAGIOS_PLUGINS_CFG_DIR |
|
42 |
+ |
|
43 |
+DO=1 |
|
44 |
+TMP=`mktemp` |
|
45 |
+echo "# 'check_mem' command definition |
|
46 |
+define command { |
|
47 |
+ command_name check_mem |
|
48 |
+ command_line $DST -w \$ARG1\$,\$ARG2\$ -c \$ARG3\$,\$ARG4\$ |
|
49 |
+}" > $TMP |
|
50 |
+ |
|
51 |
+if [ -e $NAGIOS_PLUGINS_CFG_DST ] |
|
52 |
+then |
|
53 |
+ ASK=1 |
|
54 |
+ if [ ! -n "`diff $NAGIOS_PLUGINS_CFG_DST $TMP`" ] |
|
55 |
+ then |
|
56 |
+ echo "Configuration file already and is correct. Pass." |
|
57 |
+ ASK=0 |
|
58 |
+ DO=0 |
|
59 |
+ fi |
|
60 |
+ if [ $ASK -eq 1 ] |
|
61 |
+ then |
|
62 |
+ echo "File $NAGIOS_PLUGINS_CFG_DST already exists." |
|
63 |
+ echo -n "Abort (Y,n) ? " |
|
64 |
+ read a |
|
65 |
+ [ "$a" != "N" -a "$a" != "n" ] && exit |
|
66 |
+ echo "Saved old configuration file in $NAGIOS_PLUGINS_CFG_DST.orig" |
|
67 |
+ mv "$NAGIOS_PLUGINS_CFG_DST" "$NAGIOS_PLUGINS_CFG_DST.orig" |
|
68 |
+ fi |
|
69 |
+fi |
|
70 |
+ |
|
71 |
+[ $DO -eq 1 ] && cp $TMP $NAGIOS_PLUGINS_CFG_DST |
|
72 |
+rm -f $TMP |
|
73 |
+ |
|
74 |
+ |
|
0 | 75 |