美文网首页
编写shell脚本

编写shell脚本

作者: heiheiwanne | 来源:发表于2016-11-24 10:24 被阅读82次

在实际项目中编写的几个小shell脚本

  • gradle build 启用守护进程,下次编译速度提高
#!bin/sh

./gradlew build --daemon --parallel --offline

echo "enter enyone character"
read character

adb install /Users/bjhl/Desktop/XXTT/xxtt-android/xuexitoutiao/build/outputs/apk/xuexitoutiao-zx-debug.apk
  • curl 请求链接
#!/bin/sh
#此脚本是用来使用curl请求链接的
#http://dev-app.*****.com/  dev
#http://app.****.cn/    线上

echo  "enter the request url:(topic/list)"
read url

echo  "enter the request params:(page=*&size=*&channel=**)"
read params


curl -d $params"&sig=****&client={\"appId\":\"****\",\"deviceId\":\"*****\",\"from\":\"**\",\"mac\":\"***\",\"model\":\"androidXT1085\",\"os\":\"android22\",\"version\":\"3\"}" "http://****.com/"$url

  • 脚本编译安装启动项目app
#!bin/sh
echo $(date +%Y-%m-%d:%H:%M:%S)

source ~/.bash_profile

echo "compiling..."
gradle build

echo "uninstall..."
adb uninstall  com.****.***

echo "install..."
adb install  /Users/bjhl/Desktop/***/**/***/build/outputs/apk/***-debug.apk

echo "start MainActivity..."
adb shell am start -n "com.****.***/com.***.***.MainActivity.java" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo $(date +%Y-%m-%d:%H:%M:%S)
  • 网络请求 包含cookie


#!/bin/sh
echo -n "enter the request host: "
read host # request host

#cookie
echo -n "use cookie ? (y/n)  "
read is_cookie

cookie=""

#if need cookie set
if [[ $is_cookie = "y" ]]; then
echo -n "input the cookie: "
read input_cookie
cookie=$input_cookie
fi

echo -n "need post? (y/n)  "
read tag

#http get if tag = n
if [[ $tag = "n" ]]; then
if [[ $cookie != "" ]]; then
curl $host -b$cookie
else
curl $host
fi
exit 0
fi

#the json data need to post
data=""

#the input value pair
kv_pair=""

while true; do
if [[ $tag = "y" ]]; then
#input key
echo -n "key :  "
read key

# set break condition key = gameover 这里是一个循环结束的标志.输入这个标志表示我需要传递的json数据已经全部写进去了
if [[ $key = "gameover" ]]; then
#complete the json format, %,*  start at right side and romove the first ','
kv_pair=${kv_pair%,*}

#this is the last data to post
data="{"$kv_pair"}"
echo "post data is: $data and exce the curl cmd"
#curl $host -d$data
break;
fi

#encode with ""
key='"'$key'"'

#input value
echo -n "value : "
read value

#encode value with ""
value='"'$value'"'

#set value pair and extends itself
kv_pair="$kv_pair"$key":"$value","
echo "$kv_pair"
fi

done

#do http post
if [[ $cookie != "" ]]; then
curl $host -d$data -b$cookie
else
curl $host -d$data
fi

相关文章

  • Shell script + crontab实现Mysql定时备

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

  • 多命令处理

    编写shell脚本 执行脚本

  • shell脚本

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

  • Shell脚本语法

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

  • shell脚本基础

    编写脚本 编程基础 shell脚本 创建shell脚本 变量 运算 测试 配置用户的环境

  • 78.shell编程

    shell编程 Shell脚本,是一种为shell编写的脚本程序。 Shell编程跟JavaScript、Pyth...

  • shell快速学习指南(二)

    Shell 脚本的编写 我们可以直接在shell提示符下编写shell脚本,比如函数、控制语句等都可以直接在she...

  • Shell 脚本入门: 编写格式和执行方式

    本文要点 Shell 脚本的编写规范 执行Shell 脚本文件的 3 种方式 与 区别 1. Shell 脚本的编...

  • 把Shell脚本设置为系统命令

    Shell : hello world 编写shell脚本 将shell脚本设置为在任意路径下可执行的命令 1. ...

  • 第一个shell

    编写一个shell脚本 shell脚本的开头一定要指定一个shell解释器 给shell脚本加执行权限 执行she...

网友评论

      本文标题:编写shell脚本

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