Linux两个经典脚本

1.循环删除同一个服务器中几个不同目录的文件.

#! /usr/bin/sh

set -A arr  sc_srv1,sc_srv2,sc_srv3,sc_srv4 

#clear scm log
time=`date +"%Y%m%d%"`
length=14
n=0  
while((n<length))
do
   #delete the old logs 
  find /usr/tvmlogs/* -type f -atime +7 -exec rm -rf + 

   # 
   cd  /home/${arr[n]}/monitor 
     
   #clear monitor log
   tar -cvf ${arr[n]}-$time-log.tar /home/${arr[n]}/monitor/mtlog/*
   sleep 5 
   gzip ${arr[n]}-$time-log.tar
  
   #sleep 10 seconds 
   #sleep 5
  
   mv ${arr[n]}-$time-log.tar.gz  /usr/tvmlogs/
   rm -rf ${arr[n]}-$time-log.tar 
   cd mtlog/

   echo > mtsnd.log
   echo > mtrec.log
   echo > reboot.log
   echo > error.log

 

 
   ((n=n+1))
done
 

 

 

2.使用for循环删除特定的信息

#!/sbin/sh
#name:rmipc.sh
#author:hp
#date:2010-05-22
for i in `ipcs | grep $1 | awk '$5=="tbs" {print $2}'`
do
ipcrm -m $i
ipcrm -q $i
ipcrm -s $i
done

 

 

你可能感兴趣的:(linux)