0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

nagiosのcfgを生成しやすくするスクリプト

Last updated at Posted at 2020-10-23

生成スクリプト

generate.sh
# !/bin/sh
set -eu
OUTPUT="generate.cfg"
cat /dev/null > $OUTPUT

cfg () {
    IP="$1"
    NAME="$2"
    echo "define host {" >> $OUTPUT
    echo "        use            generic-printer" >> $OUTPUT
    echo "        host_name      $NAME" >> $OUTPUT
    echo "        alias          $NAME" >> $OUTPUT
    echo "        address        $IP" >> $OUTPUT
    echo "        contact_groups admins" >> $OUTPUT
    echo "        }" >> $OUTPUT
    echo >> $OUTPUT
}

# 列挙
cfg "192.168.100.1" "myRouter"
cfg "192.168.100.2" "pc1"
cfg "192.168.100.3" "pc2"
cfg "192.168.100.4" "pc3"
sh generate.sh
  • generate.cfg が生成される。

出力例

generate.cfg
define host {
        use            generic-printer
        host_name      myRouter
        alias          myRouter
        address        192.168.100.1
        contact_groups admins
        }

define host {
        use            generic-printer
        host_name      pc1
        alias          pc1
        address        192.168.100.2
        contact_groups admins
        }

define host {
        use            generic-printer
        host_name      pc2
        alias          pc2
        address        192.168.100.3
        contact_groups admins
        }

define host {
        use            generic-printer
        host_name      pc3
        alias          pc3
        address        192.168.100.4
        contact_groups admins
        }

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?