私の意見では、UNIXオペレーティングシステムの管理者の作業を楽にすることができる私の小さな仕事に注目します。 Unixサーバーの管理者として、多くの場合、さまざまなサーバーに関する情報をアーキテクチャ委員会に提供する必要があるため、「すべてこの混乱」を書くというアイデアが生まれました。
このスクリプトの目的は、LinuxまたはAIXで実行されているサーバーに関するすべての(ほぼすべての)情報を提供することです(手元に他のUNIXファミリOSはありませんが、作業中です)。
スクリプトが機能するための要件:サーバーへの接続を実行するユーザーは、パスワードを要求せずにルートからすべてのコマンドを実行する権利を持っている必要があります(スクリプトを起動するワークステーションで-同様に、したがって、Linuxでなければなりません)。 sudoersファイル(まあ、またはLDAPでは、誰もがさまざまな方法を持っています)には行が必要です
!requiretty
最初に、sshaskpass.shという名前のファイルを作成する必要があります。次の内容が含まれます。
#!/bin/bash if [ -n "$SSH_ASKPASS_TMPFILE" ]; then cat "$SSH_ASKPASS_TMPFILE" exit 0 elif [ $# -lt 1 ]; then echo "Usage: echo password | $0 <ssh command line options>" >&2 exit 1 fi sighandler() { rm "$TMP_PWD" } TMP_PWD=$(mktemp) chmod 600 "$TMP_PWD" trap 'sighandler' SIGHUP SIGINT SIGQUIT SIGABRT SIGKILL SIGALRM SIGTERM export SSH_ASKPASS=$0 export SSH_ASKPASS_TMPFILE=$TMP_PWD [ "$DISPLAY" ] || export DISPLAY=dummydisplay:0 read password echo $password >> "$TMP_PWD" # use setsid to detach from tty exec setsid "$@" rm "$TMP_PWD"
たとえば、ホームディレクトリに置き、実行する権利を与えます(chmod + x sshaskpass.sh)。
同じディレクトリに2番目のファイルを作成し、Unix_checkという名前を付けました。好きな名前を付けることができます。
#!/bin/bash if [ ! -z $1 ]; then if ping -c1 -w1 $1 >> /dev/null 2>&1; then export HOSTNAME_NEW=$1 export USER_NAME=_ export pass=_ connect="$PWD/sshaskpass.sh ssh -o StrictHostKeyChecking=no -l $USER_NAME $HOSTNAME_NEW -n" echo "$pass" | $connect exit > /dev/null 2>&1 SYSTYPE=`echo "$pass" | $connect uname -a | awk '{print $1}'` if [ $SYSTYPE = AIX ]; then #AIX section start echo "--------------------------------------------------------------------------------" echo -en "Hostname: \t\t" echo "$pass" | $connect hostname -s echo -en "Domain: \t\t" echo "$pass" | $connect cat /etc/resolv.conf | grep domain | grep -v "#" | awk '{print $2}' echo -en "Uptime: \t\t" echo "$pass" | $connect sudo uptime | awk -F, '{print $1}' | awk '{print $3" "$4}' echo -en "Load average: \t\t" echo "$pass" | $connect sudo uptime | awk -F: '{print $NF}' | cut -c2- | awk -F, '{print $1$2$3}' cpunum(){ for i in `echo "$pass" | $connect lsdev | grep proc | grep Available | awk '{print $1}'`; do echo $i ; done } CPU=`cpunum` ch(){ for i in $CPU; do PROC1=`echo "$pass" | $connect lsattr -El $i | grep type | awk '{printf "%s", $2" "}'` PROC2=`echo "$pass" | $connect lsattr -El $i | grep frequency | awk '{print $2/1000000000 }' | awk '{printf("%.2f\n", $1)}'` echo -e "$PROC1 $PROC2" done } echo -en "Procs: \t\t\t" ch | cat -n | tail -1 | awk '{print $1"x"$2" "$3$4" GHz"}' echo -en "Cores per CPU: \t\t" echo "$pass" | $connect lsattr -El proc0 | grep smt_threads | awk '{print $2}' ips(){ IFCONFIG=`echo "$pass" | $connect ifconfig -a | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{print $2}'` for i in $IFCONFIG; do echo -en "IP: \t\t\t" echo $i done } ips macs(){ LSMACS=`echo "$pass" | $connect lsdev -Cc adapter | grep ent | grep -v EtherChannel | grep -v VLAN | grep -v Client | awk '{print $1}'` for i in $LSMACS; do echo -en "MAC: \t\t\t" echo "$pass" | $connect lscfg -vpl $i | grep Network | awk -F. '{print $14}' | sed 's/.\{2\}/&:/g' | rev | cut -c2- | rev done } macs echo -en "Mem: \t\t\t" echo "$pass" | $connect lsattr -El mem0 | grep goodsize | awk '{printf "%s", $2/1024 " Gigabytes"}' | sed -e 's/,/./' echo -e "" echo -en "Swap space:\t\t" echo "$pass" | $connect lsps -s | sed -e '1d' | awk '{print $1}' | sed 's/\(.*\)../\1/' | awk '{ tot+=$1 } END { printf "%s", tot/1024 }'; echo " Gigabytes" total(){ LSVG=`echo "$pass" | $connect lsvg` for i in $LSVG; do echo "$pass" | $connect lsvg $i | grep "TOTAL PPs" | awk '{print $7}' | sed -e 's/.//' done } echo -en "Total in VGs:\t\t" total | awk '{ tot+=$1 } END { printf "%s", tot/1024 " Gigabytes"}' | sed 's/,/./' used(){ LSVG=`echo "$pass" | $connect lsvg` for i in $LSVG; do echo "$pass" | $connect lsvg $i | grep "USED PPs" | awk '{print $6}' | sed -e 's/.//' done } echo -e "" echo -en "Used in VGs:\t\t" used | awk '{ tot+=$1 } END { printf "%s", tot/1024 " Gigabytes"}' | sed 's/,/./' free(){ LSVG=`echo "$pass" | $connect lsvg` for i in $LSVG; do echo "$pass" | $connect lsvg $i | grep "FREE PPs" | awk '{print $7}' | sed -e 's/.//' done } echo -e "" echo -en "Free in VGs:\t\t" free | awk '{ tot+=$1 } END { printf "%s", tot/1024 " Gigabytes"}' | sed 's/,/./' echo -e "" echo -en "Total in FS: \t\t" TOT1=`echo "$pass" | $connect lsfs | sed -e '1d' | grep -v "proc" | grep -v "itsm" | grep -v "jfs2 --" | awk '{print $1}'` for i in $TOT1; do echo "$pass" | $connect df -P -m $i | sed -e '1d' ; done | awk ' !x[$0]++' | awk '{print $2}' | awk '{ tot+=$1} END { print tot/1024 " Gigabytes"}' | sed -e 's/,/./' echo -en "Used in FS: \t\t" USED1=`echo "$pass" | $connect lsfs | sed -e '1d' | grep -v "proc" | grep -v "itsm" | grep -v "jfs2 --" | awk '{print $1}'` for i in $USED1; do echo "$pass" | $connect df -P -m $i | sed -e '1d' ; done | awk ' !x[$0]++' | awk '{print $3}' | awk '{ tot+=$1} END { print tot/1024 " Gigabytes"}' | sed -e 's/,/./' echo -en "Free in FS: \t\t" FREE1=`echo "$pass" | $connect lsfs | sed -e '1d' | grep -v "proc" | grep -v "itsm" | grep -v "jfs2 --" | awk '{print $1}'` for i in $FREE1; do echo "$pass" | $connect df -P -m $i | sed -e '1d' ; done | awk ' !x[$0]++' | awk '{print $4}' | awk '{ tot+=$1} END { print tot/1024 " Gigabytes"}' | sed -e 's/,/./' asm(){ RHDS=`echo "$pass" | $connect ls -la /dev/ | grep oracle | grep rhdisk | awk '{print $NF}'` for i in $RHDS; do echo "$pass" | $connect getconf DISK_SIZE /dev/$i done } echo -en "ASM space:\t\t" asm | awk '{tot+=$1} END {printf "%s", tot/1024 " Gigabytes"}' | sed 's/,/./' echo -e "" wwns(){ LSWWNS=`echo "$pass" | $connect lsdev -Cc adapter | grep -v Defined | grep fcs | awk '{print $1}'` for i in $LSWWNS; do echo -en "WWN: \t\t\t" echo "$pass" | $connect lscfg -vpl $i | grep Network | awk -F. '{print $14}' | sed 's/.\{2\}/&:/g' | rev | cut -c2- | rev done } wwns FGET=`echo "$pass" | $connect sudo mpio_get_config -Av 2>&1 | grep "Storage Subsystem Name" | awk -F= '{print $2}' | cut -c3- | rev | cut -c2- | rev` MGET=`echo "$pass" | $connect sudo fget_config -Av 2>&1 | grep "array name" | awk -F= '{print $2}' | cut -c3- | rev | cut -c2- | rev` HDLM=`echo "$pass" | $connect sudo /usr/DynamicLinkManager/bin/dlnkmgr 2>&1 view -lu | grep "SerialNumber" | awk -F: '{print $2}' | cut -c2-` for i in $FGET; do echo -en "Storage: \t\t" echo $i done for i in $MGET; do echo -en "Storage: \t\t" echo $i done for i in $HDLM; do echo -en "Storage: \t\t" echo VSP $i done echo -en "Oslevel:\t\tAIX " echo "$pass" | $connect oslevel -s echo -en "Architecture:\t\t" echo "$pass" | $connect uname -p | tr -d '\n' echo "$pass" | $connect ls -la /unix | awk '{print $NF}' | awk -F / '{print " " $NF}' | sed 's/_/\ /g' # CHECK!!!! echo -en "M/T:\t\t\t" echo "$pass" | $connect lsattr -El sys0 | grep modelname | awk '{print $2}' | cut -c5- echo -en "Serial Num:\t\t" echo "$pass" | $connect lsattr -El sys0 | grep systemid | awk '{print $2}' | cut -c7- echo "--------------------------------------------------------------------------------" sudo rm -f /tmp/tmp.* #AIX section end elif [ $SYSTYPE = Linux ]; then #Linux section start MANUF=`echo "$pass" | $connect sudo /usr/sbin/dmidecode -t system | grep Manufacturer | awk '{ print $2 }'` CPUMANUF=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep "vendor_id" | uniq | awk '{print $3}'` echo "--------------------------------------------------------------------------------" echo -en "Hostname: \t\t" echo "$pass" | $connect hostname -s echo -en "Domain: \t\t" echo "$pass" | $connect hostname -d echo -en "Uptime: \t\t" echo "$pass" | $connect sudo uptime | awk -F, '{print $1}' | awk '{print $3" "$4}' echo -en "Load average: \t\t" echo "$pass" | $connect sudo uptime | awk -F: '{print $NF}' | cut -c2- | sed -e 's/,/./g' | awk -F. '{print $1"."$2$3"."$4$5"."$6}' echo -en "Procs: \t\t\t" if [ "$MANUF" = "VMware," ]; then CPUS=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep "processor" | sort | uniq | wc -l` MODEL=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep "model name" | tail -1 | cut -c14-` if [ "$CPUMANUF" = "AuthenticAMD" ]; then SPEED=`echo "$pass" | $connect sudo /usr/sbin/dmidecode | grep "Current Speed" | head -n 1 | awk '{printf "%s", $3/1000}'` echo $CPUS $MODEL $SPEED GHz else echo $CPUS $MODEL fi CORES=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep processor | wc -l` echo -en "Cores per CPU: \t\t" echo $(( $CORES / $CPUS )) else CPUS=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l` MODEL=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep "model name" | tail -1 | cut -c14-` if [ "$CPUMANUF" = "AuthenticAMD" ]; then SPEED=`echo "$pass" | $connect sudo /usr/sbin/dmidecode | grep "Current Speed" | head -n 1 | awk '{printf "%s", $3/1000}'` echo $CPUS $MODEL $SPEED GHz else echo $CPUS $MODEL fi CORES=`echo "$pass" | $connect sudo cat /proc/cpuinfo | grep "cpu cores" | sort | uniq | awk '{print $4}'` echo -e "Cores per CPU: \t\t""$CORES" fi ips(){ IFCONFIG=`echo "$pass" | $connect sudo /sbin/ip addr | grep inet | grep -v inet6 | grep -w -v lo | awk '{print $2}'` for i in $IFCONFIG; do echo -en "IP: \t\t\t" echo $i done } ips if [ "$MANUF" = "HP" ]; then if echo "$pass" | $connect sudo rpm -aq | grep hponcfg > /dev/null; then echo "$pass" | $connect sudo /sbin/hponcfg -w /tmp/ilo > /dev/null 2>&1 ILOIP=`echo "$pass" | $connect sudo /bin/cat /tmp/ilo | grep "<IP_ADDRESS VALUE" | awk -F= '{print $2}' | cut -c3- | rev | cut -c4- | rev` echo "$pass" | $connect sudo /bin/rm /tmp/ilo else echo "$pass" | $connect sudo /bin/mkdir /tools > /dev/null 2>&1 echo "$pass" | $connect sudo /bin/mount naiad:/tools /tools echo "$pass" | $connect sudo /bin/rpm -ivh /tools/Software/hp/hponcfg-3.1.0-0.noarch.rpm > /dev/null 2>&1 echo "$pass" | $connect sudo /bin/umount /tools echo "$pass" | $connect sudo /sbin/hponcfg -w /tmp/ilo > /dev/null 2>&1 ILOIP=`echo "$pass" | $connect sudo /bin/cat /tmp/ilo | grep "<IP_ADDRESS VALUE" | awk -F= '{print $2}' | cut -c3- | rev | cut -c4- | rev` echo "$pass" | $connect sudo /bin/rm /tmp/ilo fi if ! echo "$pass" | $connect sudo rpm -aq | grep hpacucli > /dev/null; then echo "$pass" | $connect sudo /bin/mkdir /tools > /dev/null 2>&1 echo "$pass" | $connect sudo /bin/mount naiad:/tools /tools > /dev/null 2>&1 echo "$pass" | $connect sudo /usr/bin/yum install -y /tools/Software/hp/hpacucli-9.40-12.0.i386.rpm > /dev/null 2>&1 echo "$pass" | $connect sudo /bin/umount /tools > /dev/null 2>&1 fi echo -en "ILO IP: \t\t" echo $ILOIP fi macs(){ IFCONFIGM=`echo "$pass" | $connect sudo /sbin/ifconfig | grep HWaddr | awk '{print $5}' | uniq` for i in $IFCONFIGM; do echo -en "MAC: \t\t\t" echo $i done } macs echo -en "Mem: \t\t\t" echo "$pass" | $connect sudo /usr/sbin/dmidecode --type memory | grep Size | grep -v No | awk '{print $2}' | awk '{ tot+=$1 } END { printf "%s", tot/1024 }' echo -e " Gigabytes" echo -en "Swap space:\t\t" echo "$pass" | $connect cat /proc/swaps | sed -e '1d' | awk '{print $3}' | awk '{ tot+=$1 } END { printf "%s", tot/1024 }' | awk '{ tot+=$1 } END { printf "%s", tot/1024 }' | awk '{printf("%.2f\n", $1)}' | awk '{print $1 " Gigabytes"}' | sed -e 's/,/./' | sed "s/\.[00][0-9]*//g" echo -en "Total space: \t\t" echo "$pass" | $connect sudo df -m -l -P | grep -v "none" | grep -v "sda1" | grep -v "tmpfs" | sed -e '1d' | awk '{ print $2 }' | awk '{ tot+=$1} END { print tot/1024 " Gigabytes"}' echo -en "Used space: \t\t" echo "$pass" | $connect sudo df -m -l -P | grep -v "none" | grep -v "sda1" | grep -v "tmpfs" | sed -e '1d' | awk '{ print $3 }' | awk '{ tot+=$1} END { print tot/1024 " Gigabytes"}' echo -en "Free space: \t\t" echo "$pass" | $connect sudo df -m -l -P | grep -v "none" | grep -v "sda1" | grep -v "tmpfs" | sed -e '1d' | awk '{ print $4 }' | awk '{ tot+=$1} END { print tot/1024 " Gigabytes"}' if echo "$pass" | $connect rpm -aq | grep asm > /dev/null 2>&1; then nums(){ NUMS0=`echo "$pass" | $connect sudo ls -la /dev/oracleasm/disks/ 2> /dev/null | grep oracle | awk '{print $5" "$6}' | sed 's/,//g' | sed 's/ /@/g'` for i in $NUMS0; do echo $i done } nums > /tmp/asmnums drvs(){ NUMS1=`cat /tmp/asmnums` for i in $NUMS1; do DEVS=`echo "$pass" | $connect cat /proc/partitions | sed 's/ */\ /g' | sed 's/ /@/g' | grep $i | sed 's/@/ /g' | awk '{print $NF}'` echo $DEVS done } drvs > /tmp/asmdrvs echo -en "ASM space: \t\t" asm(){ BLOCK=`cat /tmp/asmdrvs` for s in $BLOCK; do echo "$pass" | $connect sudo cat /proc/partitions | sed 's/ */\ /g' | sed 's/ /@/g' | grep $s | sed 's/@/ /g' | awk '{print $3}'; done } asm | awk '{ tot+=$1 } END { print tot/1048576 " Gigabytes"}'; sudo rm -f /tmp/asmdrvs sudo rm -f /tmp/asmnums else echo -e "ASM space: \t\t0 Gigabytes" fi wwns(){ LSWWNS=`echo "$pass" | $connect sudo /usr/bin/systool -c fc_host -v 2> /dev/null | grep port_name | awk -F= '{print $2}' | cut -c5- | rev | cut -c2- | rev | sed 's/.\{2\}/&:/g' | rev | cut -c2- | rev` for i in $LSWWNS; do echo -en "WWN: \t\t\t" echo $i done } wwns if echo "$pass" | $connect sudo ls /usr/sbin/mppUtil > /dev/null 2>&1 /dev/null; then RDAC=`echo "$pass" | $connect sudo /usr/sbin/mppUtil -a 2>/dev/null | grep FC | awk '{print $NF}'` for i in $RDAC; do echo -en "Storage: \t\t" echo $i done fi echo -en "Oslevel: \t\t" if echo "$pass" | $connect sudo ls /etc/redhat-release > /dev/null 2>&1; then echo "$pass" | $connect cat /etc/redhat-release elif echo "$pass" | $connect sudo ls /etc/SuSE-release > /dev/null 2>&1; then echo "$pass" | $connect cat /etc/SuSE-release | head -1 elif echo "$pass" | $connect sudo ls /etc/gentoo-release > /dev/null 2>&1; then echo "$pass" | $connect cat /etc/gentoo-release elif echo "$pass" | $connect sudo ls /etc/debian_version > /dev/null 2>&1; then echo "$pass" | $connect cat /etc/os-release | grep PRETTY | awk -F= '{print $2}' | cut -c2- | rev | cut -c2- | rev fi echo -en "Kernel ver: \t\t" echo "$pass" | $connect uname -r echo -en "Architecture: \t\t" echo "$pass" | $connect uname -a | awk '{print $12}' echo -en "Manufacturer: \t\t" if [ "$MANUF" = "VMware," ]; then echo "Vmware" else echo "$MANUF" fi echo -en "Model: \t\t\t" echo "$pass" | $connect sudo /usr/sbin/dmidecode -t system | grep "Product Name" | cut -c16- echo -en "Serial Num: \t\t" echo "$pass" | $connect sudo /usr/sbin/dmidecode -t system | grep "Serial Number" | cut -c17- if [ "$MANUF" = "HP" ]; then HDDFAIL=`echo "$pass" | $connect sudo /usr/sbin/hpacucli ctrl all show config | grep "physicaldrive" | grep -v OK | cut -c7-` if [ ! -z "$HDDFAIL" ]; then echo -e "HDD Error: \t\t"$HDDFAIL fi fi echo "--------------------------------------------------------------------------------" sudo rm -f /tmp/tmp.* #Linux section end elif [ $SYSTYPE = FreeBSD ]; then #FreeBSD section start echo "FreeBSD" #FreeBSD section end elif [ $SYSTYPE = SunOS ]; then #Solaris section start echo "Solaris" #Solaris section end elif [ $SYSTYPE = HP-UX ]; then #HP-UX section start echo "HP-UX" #HP-UX section end fi else echo "unknown host $1" fi else echo "hostname or ip must be specified (Unix_check hostname/ip)" fi
したがって、私たちは彼に打ち上げの権利も与えます。
次のように実行します。./Unix_check hostname
AIXの例:
-------------------------------------------------------------------------------- Hostname: tsm Domain: xxxxxxx.xxxxx.ua Uptime: 30 days Load average: 0.00 0.00 0.02 Procs: 2xPowerPC_POWER5 2.10 GHz Cores per CPU: 2 IP: 172.17.xx.xx MAC: 00:14:5E:97:xx:xx MAC: 00:14:5E:97:xx:xx Mem: 7.75 Gigabytes Swap space: 5 Gigabytes Total in VGs: 1252.5 Gigabytes Used in VGs: 562.25 Gigabytes Free in VGs: 690.25 Gigabytes Total in FS: 527.375 Gigabytes Used in FS: 461.424 Gigabytes Free in FS: 65.9507 Gigabytes ASM space: 0 Gigabytes WWN: 10:00:00:00:C9:4F:xx:xx WWN: 10:00:00:00:C9:4F:xx:xx Storage: 181470A-78K0xxx-tsm-F Storage: 181470A-78K0xxx-tsm-D Oslevel: AIX 6100-07-03-1207 Architecture: powerpc unix 64 M/T: 9131-52A Serial Num: XXXXXX --------------------------------------------------------------------------------
Linuxの例
-------------------------------------------------------------------------------- Hostname: dfilendbb01 Domain: xxxx.xxxx.xxx Uptime: 5 days Load average: 0.00 0.02 0.00 Procs: 2 Dual-Core AMD Opteron(tm) Processor 2218 2.6 GHz Cores per CPU: 2 IP: 172.17.xx.xx/xx ILO IP: 172.17.xx.xx MAC: 00:21:5A:49:xx:xx Mem: 8 Gigabytes Swap space: 8 Gigabytes Total space: 71.0547 Gigabytes Used space: 31.0742 Gigabytes Free space: 36.3203 Gigabytes ASM space: 0 Gigabytes WWN: 50:01:43:80:02:9f:xx:xx WWN: 50:01:43:80:02:9f:xx:xx Oslevel: Red Hat Enterprise Linux Server release 5.9 (Tikanga) Kernel ver: 2.6.18-348.3.1.el5 Architecture: x86_64 Manufacturer: HP Model: ProLiant BL465c G1 Serial Num: CZJ8300xxx HDD Error: physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 146 GB, Predictive Failure) --------------------------------------------------------------------------------
HPのRHEL用パッケージ(hponcfgおよびhpacucli)でNFSボールをマウントするなど、一部のパスを変更する必要があります。
また、Linuxの場合、スクリプトはユーティリティを使用して、SANを介して接続され、ネイティブmultipathdではなくRDACを使用して接続されたIBMディスクラックを識別します。 AIXの場合、直接接続されたすべてのラックを表示する必要があります(VIOSおよびVSCSIなし)。
AIXは、Oracle ASMのディスクサイズを決定する際に、LVMを使用せずにhdisk全体を割り当てる方法を使用します。
Linuxでは、Oracle ASMのディスクサイズは常に正しく機能するはずです。少なくともディスクを表示する他の方法はわかりません。
HPが製造したサーバーの場合、スクリプトは組み込みRAIDアダプターのディスクエラーをチェックします。
提供された情報が誰かに役立つことを嬉しく思います。同様に、私に宛てられた批判を聞く準備ができています。
PS注意深い読者は、FreeBSD、Solaris、HP-UXに関連する主要なスクリプト行の最後に、これらのセクションがまだ準備できていないことを確認します。前述したように、これらのOSは手元にありません。 評判の良いコミュニティが将来この記事を編集する権利を与えてくれた場合、言及されたシステムが登場するので、スクリプトを補足します。
ご清聴ありがとうございました。