6/23/2011

DebianでmultiNIC設定

Debian6.0でmultiNICの設定が分からなくてはまってしまったので忘れないうちにメモ。
Redhatと比べるとstatic-routeの記載がめんどい。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 10.1.1.10
        netmask 255.255.192.0
        network 10.1.0.0
        broadcast 10.1.1.255
        #gateway 10.1.0.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 10.1.1.8 10.1.1.9
        post-up route add -net 10.5.0.0 netmask 255.255.0.0 gw 10.1.0.1
        post-up route add -net 10.6.0.0 netmask 255.255.0.0 gw 10.1.0.1
        pre-down route del -net 10.5.0.0 netmask 255.255.0.0 gw 10.1.0.1
        pre-down route del -net 10.6.0.0 netmask 255.255.0.0 gw 10.1.0.1


allow-hotplug eth1
iface eth1 inet static
        address 10.2.1.10
        netmask 255.255.192.0
        network 10.2.0.0
        broadcast 10.2.1.255
        gateway 10.2.0.1
        dns-nameservers 10.2.1.8 10.2.1.9
        post-up route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.2.0.1
        pre-down route del -net 0.0.0.0 netmask 0.0.0.0 gw 10.2.0.1

6/14/2011

対話メニュー形式のshell

対話式のshellは操作する人を拘束してしまうので悪とされているけれど、何かと需要があったので対話メニュー形式のshellを作ってみた。
#!/bin/sh

# Yes or No function
# return value Yes:0 No:1 Other:2
YN ()
{
        read -p $1 YESNO
        case ${YESNO} in
                "y" | "Y")
                        return 0
                ;;
                "n" | "N")
                        return 1
                ;;
                *)
                        echo "Input number out of range. Please press enter key."
                        read wait
                        return 2
                ;;
        esac
}

# Blank Function
# echo Blank-Line
BLANK()
{
        echo ""
        echo "/-- Check results --/"
        echo ""
}

# ANYKEY Function
# Pause operation
ANYKEY ()
{
        echo ""
        echo "Please press enter key."
        read wait
}

# Get executetime function
# Output format:YYYYMMDD_hhmmss
GETTIME ()
{
        SYSTEMTIME=`date '+%Y%m%d_%H%M%S'`
        echo ${SYSTEMTIME}
}

stty erase ^H
RTNCD=1
# It Executes until return value "0"
while [ ${RTNCD} = 1 ]; do
        # Output menu list
        clear
        echo "                          Menu"
        echo ""
        echo "  1.  Change Logfile Permission"
        echo "  2.  Copy messages file"
        echo "  99. Exit Menu"
        echo ""
        echo ""

        # Read from standard input
        read -p "Input Number -->" INPUT
        case ${INPUT} in
        1)
                echo "Change Logfile Permission"
                if YN "Do?(Y/N)>"; then
                        chmod 644 /var/log/messages
                        BLANK
                        ls -l /var/log/messages
                        ANYKEY
                        RTNCD=1
                else
                        echo "Boo"
                        RTNCD=1
                fi
        ;;
        2)
                echo "Copy messages file"
                if YN "Do?(Y/N)>"; then
                        cp -p /var/log/messages /var/log/messages.`GETTIME`
                        BLANK
                        ls -l /var/log/messages*
                        ANYKEY
                        RTNCD=1
                else
                        echo "Boo"
                        RTNCD=1
                fi
        ;;
        99)
                RTNCD=0
                echo "bye"
        ;;
        *)
                echo "Input number out of range."
                ANYKEY
        ;;
        esac
done

case文に色々追記していけばそこそこ使えるかも。

teratermマクロを使って操作ログの自動取得

こんな感じでマクロを作成
username = 'user'
hostname = '192.168.1.1'
HostID   = 'Server001'
gettime timestr "%Y%m%d-%H%M%S"
getenv 'USERNAME' opeuser

logname = 'C:\log\'
strconcat logname HostID
strconcat logname '_'
strconcat logname timestr
strconcat logname '_'
strconcat logname opeuser
strconcat logname '.log'
logopen logname 0 0 1 0 1

msg = 'Enter '
strconcat msg username
strconcat msg ' user Password'
passwordbox msg 'password'

msg = hostname
strconcat msg ':22 /ssh /auth=password /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg inputstr

connect msg
sendln ''

C:\logに"hostname_YYYYMMDD-HHMMSS_ログインユーザ名.log"形式で勝手に作成。
あと、teraterm-menuを併用すれば1クリック、パスワード入力で接続できるようになる。

タイムスタンプが付加できれば、より良いんだけどうまい方法が見つからず・・・