几个bash代码

来源:互联网 发布:招商重工 软件著作权 编辑:程序博客网 时间:2024/06/06 09:39

一、编译文件夹中的文件

#!/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-repositorycopyfile /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 1fipids=`ps -ef |grep $1 | grep -v grep |grep -v 'Controller'| grep 'icebox' |awk '{print $2}'`echo $pidsecho "---------------------"for pid in $pidsdo  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" ]; docase $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;;esacdoneecho "type is $type"echo "start is $startTime. end is $endTime"




原创粉丝点击