美文网首页
Shell小脚本

Shell小脚本

作者: shadow000902 | 来源:发表于2017-11-10 19:53 被阅读44次
删除目录下的除今天外的所有文件夹
  1. 目录下的文件夹规律【年月日时分秒】
# taoyi @ TaoYi-Mac in ~/Desktop/test0001 [15:54:29] 
$ ll
total 0
drwxr-xr-x  2 taoyi  staff    68B 11  3 18:29 20171027121219
drwxr-xr-x  3 taoyi  staff   102B 11  3 18:30 20171101124273
drwxr-xr-x  3 taoyi  staff   102B 11  3 18:29 20171102124212
drwxr-xr-x  2 taoyi  staff    68B 11  3 18:29 20171103121216
drwxr-xr-x  3 taoyi  staff   102B 11  3 18:29 20171103124211
drwxr-xr-x  2 taoyi  staff    68B 11  3 18:29 20171103124216
drwxr-xr-x  2 taoyi  staff    68B 11  3 18:29 20171104124212
  1. shell脚本
# 目录下的所有文件夹名称写入文件``dir``
ls -l /Users/taoyi/Desktop/test0001/ | awk '/^d/ {print $NF}' > /Users/taoyi/Desktop/test0001/dir

# `date +%Y%m%d`,获取当天的年月日
for i in $(grep -v `date +%Y%m%d` /Users/taoyi/Desktop/test0001/dir)
do
    # 删除目录下的文件夹
    rm -rf /Users/taoyi/Desktop/test0001/$i
done

# 删除零时写入的文件``dir``
rm -rf /Users/taoyi/Desktop/test0001/dir                                                                                
kill指定name的pid
# kill指定name的pid
# 示例:"./kill_pidname.sh jhost"

pid_name=$1
ps -ef | grep -v grep | grep $pid_name | while read username pid other
do
    kill -9 $pid
done
adb截图导出并展示
# 调用安卓系统内部截图命令screencap截图保存
adb shell /system/bin/screencap -p /sdcard/screenshot.jpg
# 导出图片到本地目录
adb pull /sdcard/screenshot.jpg ~/shell-tools/ScreenShots/
# 打开图片
open ~/shell-tools/ScreenShots/screenshot.jpg
android打包并安装
cd /Users/taoyi/git_projects/Gitlab/androidclientnative/
git checkout develop
git pull

rm -rf /Users/taoyi/git_projects/Gitlab/androidclientnative/app/build/
rm -rf /Users/taoyi/shell-tools/APK/*.apk

gradle clean assembleFengcheBeta
# gradle clean assembleFengchePreview
# gradle clean assembleFengcheRelease

cp -rf /Users/taoyi/git_projects/Gitlab/androidclientnative/app/build/outputs/apk/beta/*.apk /Users/taoyi/shell-tools/APK/
adb uninstall com.souche.fengche
adb install /Users/taoyi/shell-tools/APK/*.apk
Shell脚本解析xml文件字段

示例文件内容build.xml

  <parameters>
    <hudson.model.StringParameterValue>
      <name>SCHEME</name>
      <description>scheme configuration of this project StoreCI</description>
      <value>Coding_iOS</value>
    </hudson.model.StringParameterValue>
    <hudson.model.StringParameterValue>
      <name>CONFIGURATION</name>
      <description>configuration of packing, Release/Debug</description>
      <value>Release</value>
    </hudson.model.StringParameterValue>
    <hudson.model.StringParameterValue>
      <name>OUTPUT_FOLDER</name>
      <description>output folder for build artifacts, it is located in workspace/project root dir.</description>
      <value>build_outputs</value>
    </hudson.model.StringParameterValue>
    <hudson.model.StringParameterValue>
      <name>BRANCH</name>
      <description>git repository branch</description>
      <value>master</value>
    </hudson.model.StringParameterValue>
  </parameters>
  <causeBag class="linked-hash-map">
    <entry>
      <hudson.model.Cause_-UserIdCause>
        <userId>shadow</userId>
      </hudson.model.Cause_-UserIdCause>
      <int>1</int>
    </entry>
  </causeBag>
# 获取<userId>shadow</userId>中的shadow
sed -n 's/.*>\(.*\)<\/userId>/\1/p' $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/build.xml
# 获取<userId>shadow</userId>中的shadow,赋值给userId
# 使用位置:Jenkins获取构建人
userId=(`sed -n 's/.*>\(.*\)<\/userId>/\1/p' $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/build.xml`)
Shell脚本获取文本特定字段
# 获取log文件第一行中,``[0m``字符后面的所有字符
head -1 $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/log | awk -F '\\[0m' '{print $NF}'
Jenkins获取构建人,并赋值到变量并使用

取值shell

head -1 $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/log | awk -F '\\[0m' '{print $NF}' > userId
read userId < userId
echo "userId=${userId}" > userId.txt

set Build Name中加入构建人

${PROPFILE,file="userId.txt",property="userId"}
Jenkins获取安卓APP版本号并赋值给变量并使用

取值shell

versionName=`cat app/gradle.properties | grep 'VERSION_NAME' | cut -d '=' -f 2 `
echo "versionName=${versionName}" > versionName.txt

set Build Name中加入安卓APP版本号

${PROPFILE,file="versionName.txt",property="versionName"}

相关文章

  • Shell入门笔记

    Shell脚本:Linux Shell脚本学习指南菜鸟教程 - Shell教程Linux入门 - Shell脚本是...

  • 2018-09-26

    shell脚本 1.1、什么是shell脚本(shell script , ...

  • Shell script + crontab实现Mysql定时备

    一、Shell 脚本 Shell 脚本(shell script),是一种为 shell 编写的脚本程序。 业界所...

  • 嵌入式day12

    shell脚本的本质 shell脚本语言是解释型语言 shell脚本的本质:shell命令的有序集合 shell编...

  • shell脚本

    什么是shell脚本 Shell 脚本(shell script),是一种为 shell 编写的脚本程序。业界所说...

  • Shell脚本语法

    1. Shell脚本简介Shell 脚本(shell script),是一种为 shell 编写的脚本程序。业界所...

  • Shell 脚本中的小技巧

    Shell 脚本中的小技巧 关于变量 一,在shell 脚本中定义默认值 [图片上传失败...(image-54c...

  • shell脚本

    什么是Shell脚本 Shell脚本(英语:Shell script),又称Shell命令稿、程序化脚本,是一种电...

  • 【生物信息笔记】shell 脚本 (dry-2)

    shell 和 shell script(脚本)区别: shell 和 shell 脚本是两个不同概念,shell...

  • chapter 11. 构建基本脚本

    创建shell脚本 shell脚本第一行为指定具体shell来运行该脚本,可以指定shell(待验证) echo ...

网友评论

      本文标题:Shell小脚本

      本文链接:https://www.haomeiwen.com/subject/qkdimxtx.html