及其简单的shell Script脚本


#!/bin/bash
#2017-02-09
#get pdf file
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/app/soft/jdk1.7.0_79/bin:/home/anxin/bin
export PATH
echo "this is get pdf file and today is "$(date +%Y%m%d)
read -p "please input policyNo:" file
read -p "please input file year:" year

/bin/cp /app/axtmp/pdf/${year}/store/${file}.pdf /app/axtmp/
/bin/cp /app/axtmp/pdf/${year}/signed/${file}.pdf /app/
echo "store file is /app/axtmp/ , signed file is /app/"

自己写的第一个shell script脚本

 

1 grep --color=auto -C 10 '15011580080' catalina.out   //在该文件中查找字符串出现的位置并高亮,以及上下10行

 成型脚本

 1 #!/bin/bash
 2 set -x
 3 #2017-06-10
 4 #this shell script is test
 5 PATH=/app/jdk8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/app/maven/bin
 6 export PATH
 7 KEY=$1
 8 FILENAME=/app/test/test.xml
 9 NOWPATH=`pwd`
10 NOWPATH=${NOWPATH}"/"
11 grep -H "$KEY" *.xml | cut -d : -f 1 >/app/test/test.xml
12 for line in `cat $FILENAME`
13 do
14    file=${NOWPATH}${line}
15    cp "$file" /app/test
16 done 
17 exit 0

sh 脚本名   参数 //执行方式

需要修改文件权限,变成可执行文件

chmod +x filename

 

$1   取参数的值

大致是:查询当前目录下的所有的包含参数的xml文件,保存到/app/test/test.xml文件中,然后循环读取该文件内容将所有的文件拷贝到/app/test这个目录下。

posted @ 2017-02-09 11:13  默默行走  阅读(515)  评论(0编辑  收藏  举报