コンテンツへスキップ

シェル

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
import commands

args = sys.argv
argc = len(args)

if (argc < 2):
    print "Usage:\n" +  args[0] + "設定ファイル\" \"プロパティファイル\""
    quit()

CONF_FILE = args[1]
PROP_FILE = args[2]

f = open(PROP_FILE)
lines = f.readlines()
f.close()

for line in lines:
    line = line.strip()

    p = line.split("=")
    prop_title = p[0] + "="
    prop_val = p[1].strip()

    com = "grep \"" + prop_title + "\"" + " " + CONF_FILE
    ret = commands.getoutput(com)

    if ret == "":
        com = "sysctl -a | grep \"" + prop_title + "\""
        ret = commands.getoutput(com)
        com_type = "s"
    else:
        com_type = "f"

    p2 = ret.split("=")
    prop_val_sysctl = p2[1].strip()

    if prop_val == prop_val_sysctl:
        res = "O"
    else:
        res = "X"

    print res + "," + "," + com_type + "," + prop_title + "," + prop_val_sysctl + "," + prop_val

確認したいパラメータを書いたファイル

net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 3
kernel.shmmax = 4
net.ipv6.ip6frag_time = 5

使い方

[root@centos65sono1 SysctlCheck]# ./propCheck.py "/etc/sysctl.conf" "test.txt"
O,,f,net.ipv4.tcp_syncookies =,1,1
O,,f,kernel.msgmnb =,65536,65536
X,,f,kernel.msgmax =,65536,3
X,,f,kernel.shmmax =,68719476736,4
X,,s,net.ipv6.ip6frag_time =,60,5