一、编译文件夹中的文件
#!/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"