利用shell进行批量操作

利用shell进行批量操作
下面的shell语句是可以批量杀死进程包含rec的进程,并且利用awk输出进程号

1  for  i  in  `ps  - ef | grep rec | grep  - v grep  | awk  ' {print $2} ' `
2   do 
3     echo $i 
4     kill  - 9  $i 
5   done 

下面的语句是删除各个业务文件夹下面的文件
for  business  in  datum 
do

find $SETTLE_DATA
/ filter / error_file / $business /      - type f  - exec  rm {} \;
find $SETTLE_DATA
/ filter / index / $business /           - type f  - exec  rm {} \;
find $SETTLE_DATA
/ filter / index_work / $business /      - type f  - exec  rm {} \;
find $SETTLE_DATA
/ filter / repeat / $business /          - type f  - exec  rm {} \;
find $SETTLE_DATA
/ filter / special / $business /         - type f  - exec  rm {} \;
find $SETTLE_DATA
/ filter / rollback / $business /        - type f  - exec  rm {} \;

done

下面的语句是判断文件夹是否为空
# !/usr/bin/sh

output_message()
{
                
if  [ !  - d $SETTLE_DATA / $model / $parent_dir / $business ]
                then
                echo 
" \t\t\t\t\t\t$SETTLE_DATA/$model/$parent_dir/$business is not a directory! " ;
                
elif  [ `ls $SETTLE_DATA / $model / $parent_dir / $business  |  wc  - l`  - gt 0 ]
                         then
                echo 
" \t\t\tThe directory $SETTLE_DATA/$model/$parent_dir/$business is not empty! " ;
                        
else
                echo 
" The directory $SETTLE_DATA/$model/$parent_dir/$business is empty! " ;
                fi
}

for  business  in  datum
do
                
for  model  in  filter indb
                do
                    
# M-EM-EM-VM-X
                     if  [ $model  =  filter ]
                    then
                                
for  parent_dir  in  error_file index index_work repeat special rollback
                                do
                                   output_message
                                done
                    
# M-HM-kM-?M-b
                     elif  [ $model  =  indb ]
                    then
                                      
for  parent_dir  in  temp notin errin work backup
                                      do
                                                                         output_message
                                      done
                    fi
                done
done

你可能感兴趣的:(利用shell进行批量操作)