几个bash代码

一、编译文件夹中的文件

#!/bin/bash

#递归遍历jar 包
copyfile() {
  echo '$1',$1,'   $2',$2
  for item in `ls $1`
  do  
    item_path=$1"/"$item
    if [ -d $item ]; then
      echo 'dir:'$item_path
      cd $item
      copyfile $item_path $2
      cd ..
    elif [ -f $item ]; then
      echo 'file:'$item_path
      ret=`echo $item  | grep "\.jar" |grep -v 'sha1' |grep -v "[0-9]\.jar"`
      if [ ! "$ret" = "" ]; then
        cp $item_path $2
      fi  
    fi  
  done
}
cd /data/maven-repository
copyfile /data/maven-repository  /trunk/jarpackage

二、 获取日期格式

today=`date`
year=`date -d '3 days ago' +%F|cut -d "-" -f 1`
month=`date -d '3 days ago' +%F|cut -d "-" -f 2`
day=`date -d '3 days ago' +%F|cut -d "-" -f 3`
day_7=`date -d '7 days ago' +%F|cut -d "-" -f 3`
day_1=`date -d '1 days ago' +%F|cut -d "-" -f 3`
date -d "now" +"%Y%m%d"    #20130702

#echo `date '+%Y-%m-%d'` - $hst >> /root/wap/plog_clear.log
#rm -rf /data/server_log/push-server/*.log.$year-$month-$day_7*
rm -rf /data/web_log/log/xoa/flashscreen/*.log.$year-$month-"$day_1" 


三、杀进程

if [ $# -ne 1 ]; then
  echo 'parameters error'
  exit 1
fi
pids=`ps -ef |grep $1 | grep -v grep |grep -v 'Controller'| grep 'icebox' |awk '{print $2}'`
echo $pids
echo "---------------------"
for pid in $pids
do
  kill -9 $pid
  echo "pid: $pid killed"
done

四、循环处理字符串

SERV=("10.3.24.21 10.3.24.22 10.3.24.23 10.3.24.24 10.7.16.25 10.7.16.26 ")
for i in ${SERV[@]}; do
    echo $i
#   /usr/bin/ssh ${FLAG} root@${i} "echo '$2@XIAONEI.OPI.COM' >> ~/.k5login"
done

五、输入

while [ -n "$1" ]; do
case $1 in
   -h) help;shift 1;; # function help is called
   -type) type=$2;shift 1;; # variable opt_f is set
   -time) startTime=$2;endTime=$3;shift 3;; # -l takes an argument -> shift by 2
   *) break;;
esac
done

echo "type is $type"
echo "start is $startTime. end is $endTime"




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值