Cleanup config.nodes_of
[check_mk.git] / agents / plugins / runas
blob61bef912b8d32c2cf24a18835c5afc726bd2c0ca
1 #!/bin/bash
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
9 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
26 # This plugin allows to execute mrpe, local and plugin skripts with a different user context
27 # It is configured with in the file $MK_CONFDIR/runas.cfg
29 # Syntax:
30 # [Script type] [User context] [File / Directory]
32 # Example configuration
33 # # Execute mrpe commands in given files under specific user
34 # # A '-' means no user context switch
35 # mrpe ab /home/ab/mrpe_commands.cfg
36 # mrpe lm /home/lm/mrpe_commands.cfg
37 # mrpe - /root/mrpe/extra_commands.cfg
39 # Excecute -executable- files in the target directories under specific user context
40 # plugin ab /var/ab/plugins
41 # local ab /var/ab/local
44 grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/runas.cfg" | \
45 while read type user include
47 if [ -d $include -o \( "$type" == "mrpe" -a -f $include \) ] ; then
48 PREFIX=""
49 if [ "$user" != "-" ] ; then
50 PREFIX="su $user -c "
53 # mrpe includes
54 if [ "$type" == "mrpe" ] ; then
55 echo "<<<mrpe>>>"
56 grep -Ev '^[[:space:]]*($|#)' "$include" | \
57 while read descr cmdline
59 PLUGIN=${cmdline%% *}
60 if [ -n "$PREFIX" ] ; then
61 cmdline="$PREFIX\"$cmdline\""
63 OUTPUT=$(eval "$cmdline")
64 echo -n "(${PLUGIN##*/}) $descr $? $OUTPUT" | tr \\n \\1
65 echo
66 done
67 # local and plugin includes
68 elif [ "$type" == "local" -o "$type" == "plugin" ] ; then
69 if [ "$type" == "local" ] ; then
70 echo "<<<local>>>"
72 find $include -executable -type f | \
73 while read filename
75 if [ -n "$PREFIX" ] ; then
76 cmdline="$PREFIX\"$filename\""
77 else
78 cmdline=$filename
80 $cmdline
81 done
84 done