[Shell] monitor filesystem

tolilong發表於2016-02-28
oracle6機器是收集filesystem的機器,訪問其他的linux伺服器
按照monitor cpu&mem的順序,
配置/etc/hosts,建立user,配置ssh


1.建立table
Table created.SQL> create table mon_filesystem
  2  (hostname varchar2(20),  
  3   filesystem varchar2(100),
  4   allbytes  varchar2(30),
  5   usebytes  varchar2(30),
  6   freebytes varchar2(30),
  7   usepct varchar2(10),   
  8   mounton varchar2(100),
  9   mon_datetime varchar2(50)
 10  );


2.shell script
[mon@oracle6 source]$ more mon_filesystem 
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=xxxxxdb
DATETIME=`date +"%Y/%m/%d %H:%M:%S"`


HOSTNAME=/home/mon/source/mon_cpumem_hostname
FILESYSTEM=/home/mon/data/filesystem.txt


cat $HOSTNAME | while
   read LINE
do
   echo "df -P" | ssh -Tq mon@$LINE > $FILESYSTEM
   cat $FILESYSTEM | grep % | grep -v .gvfs | while
      read NLINE
   do
      FILESYSTEM=`echo $NLINE | awk '{print $1}'`
      ALLBYTES=`echo $NLINE | awk '{print $2}'`
      USEBYTES=`echo $NLINE | awk '{print $3}'`
      FREEBYTES=`echo $NLINE | awk '{print $4}'`
      USEPCT=`echo $NLINE | awk '{print $5}'`
      MOUNTON=`echo $NLINE | awk '{print $6}'`
      $ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_filesystem.log
      insert into mon_filesystem values ('$LINE','$FILESYSTEM','$ALLBYTES','$USEBYTES','$FREEBYTES','$USEPCT','$MOUNTON','$DATETIME');
      commit;
      exit;
EOF


   done


done


3.定時任務crontab
[mon@oracle6 source]$ crontab -l
13 7,15,23 * * * /home/mon/source/mon_filesystem > /dev/null 2>&1

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2015510/,如需轉載,請註明出處,否則將追究法律責任。

相關文章