安卓猿的ADB骚操作

前言当前PC连着多个安卓设备时,当超出了 adb 所支持的设备数,步骤如下: adb devices 列出你当前的设备列表,然后拷贝你要安装的设备Device Id; 使用 adb -s deviceIdinstall .... 来进行 APK 安装error: more than one device/emulatoradb: error: failed to get feature set: more than one device/emulator- waiting for device -error: more than one device/emulator效果图 #adb 快捷命令function adbConnect(){ echo "Your connect is 192.168.$1" # 这个 $1 必须要参考底下命令的下达 adb connect 192.168.$1}function adbDisconnect(){ adb disconnect}function adbShell(){ adb shell}function devices(){ adb devices}# 获取安卓设备数量function getAdbDevicesCount(){ no_dev=2 #没有设备的总行数 第一行: List of devices attached 第二行 空 line="`adb devices | wc -l`" # echo "$line" echo $(($line-$no_dev))}#获取自定义格式设备名称 参数1: adb devices 设备ID indexfunction getFmtDeviceName(){ if [ -n "$1" ]; then line=$1 let "line++" #跳过1行 deviceId="`adb devices | sed -n "${line}p" | awk '{printf $1"\n"}' `" # name="`adb devices | sed -n "2p;${line}p" | awk '{printf NR ". " $1"\n"}' `" #简单列出设备ID manufacturer="`adb -s $deviceId shell getprop ro.product.manufacturer`" model="`adb -s $deviceId shell getprop ro.product.model`" version="`adb -s $deviceId shell getprop ro.build.version.release`" sdk="`adb -s $deviceId shell getprop ro.build.version.sdk`" name="${manufacturer} ${model} Android ${version} API ${sdk} Serial: ${deviceId} " # 去除某些设备后面携带回车符 name=`echo ${name} | tr -d '\r'` echo ${name} else echo "requires an argument" fi}# 列出所有设备function listFmtDevices(){ count=`getAdbDevicesCount` index=1 while(( $index<=count )) do name=`getFmtDeviceName ${index}` echo "${index}. ${name} " let "index++" done}# 获取设备ID 参数1: adb devices 设备ID indexfunction getFmtDeviceId(){ if [ -n "$1" ]; then line=$1 let "line++" #跳过1行 deviceId="`adb devices | sed -n "${line}p" | awk '{printf $1"\n"}' `" # 去除某些设备后面携带回车符 deviceId=`echo ${deviceId} | tr -d '\r'` echo ${deviceId} else echo "requires an argument" fi}# 安装apkfunction apk(){ if [ -n "$1" ]; then count=`getAdbDevicesCount` one_dev=1 if [ $count -eq $one_dev ] then # 单设备 name=`getFmtDeviceName 1` echo "install apk to devices: ${name}" adb install -r $1 elif [ $count -gt $one_dev ] then # 多设备 if [ -n "$2" ]; then # 带设备index index=$2 deviceId=`getFmtDeviceId ${index}` name=`getFmtDeviceName ${index}` echo "install apk to devices: $name" adb -s $deviceId install -r $1 else # 带apk文件路径 echo "install apk to which devices?" listFmtDevices read -p "Enter: " index apk $1 $index fi else echo "no devices" fi else echo "apk requires an apkPath argument" fi}# 卸载apkfunction uapk(){ if [ -n "$1" ]; then count=`getAdbDevicesCount` one_dev=1 if [ $count -eq $one_dev ] then # 单设备 name=`getFmtDeviceName 1` echo "uninstall apk on $name" adb uninstall $1 elif [ $count -gt $one_dev ] then # 多设备 if [ -n "$2" ]; then # 带设备index index=$2 deviceId=`getFmtDeviceId ${index}` name=`getFmtDeviceName ${index}` echo "uninstall apk on devices: $name" adb -s $deviceId uninstall $1 else # 带apk文件路径 echo "uninstall apk on which devices?" listFmtDevices read -p "Enter: " index uapk $1 $index fi else echo "no devices" fi else echo "uapk requires an pkg argument" fi}# 进入adb shell 环境function as(){ count=`getAdbDevicesCount` one_dev=1 if [ $count -eq $one_dev ] then # 单设备 name=`getFmtDeviceName 1` echo "${name} Last login: `date`" adb shell elif [ $count -gt $one_dev ] then # 多设备 if [ -n "$1" ]; then # 带设备index index=$1 deviceId=`getFmtDeviceId ${index}` name=`getFmtDeviceName ${index}` echo "${name} Last login: `date`" adb -s $deviceId shell else # 不带设备index echo "enter shell which devices?" listFmtDevices read -p "Enter: " index as $index fi else echo "no devices" fi}

June 15, 2019 · 3 min · jiezi

crontab 在mac上不执行问题研究

crontab是个管理定时任务的工具,作用是在特定时间(通过crontab的语法配置),自动执行特定任务(想让它执行什么,就写个脚本或bash命令)。当你每天都需要执行脚本干一些重复工作的时候,这个东西就派上用场了。不了解这个东西怎么用的朋友,可以通过点击这里进行一个基本了解。这篇文章主要是为了记录自己在写crontab时踩得一些坑,当我按照顺序做完配置之后,却发现crontab中的task怎么也跑步起来,于是google了一下问题,找到了几个相关blog,结合在一起验证,终于解决了问题。crontab 为啥不执行呢?问了一下谷歌,OS X的定时任务统统由 launchctl 来管理的,看看 cron 任务有没有在里面 ➜ ~ sudo launchctl list | grep cron 208 0 com.vix.cron 有记录。查看一下启动项的配置。 ➜ ~ locate com.vix.cron WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear.database 不存在啊,那就创建一个吧。 sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist // 这个指令会花费一定时间一段时间后,创建成功,然后查看~ cat /System/Library/LaunchDaemons/com.vix.cron.plist<?xml version=“1.0” encoding=“UTF-8”?><!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version=“1.0”><dict> <key>Label</key> <string>com.vix.cron</string> <key>ProgramArguments</key> <array> <string>/usr/sbin/cron</string> </array> <key>KeepAlive</key> <dict> <key>PathState</key> <dict> <key>/etc/crontab</key> <true/> </dict> </dict> <key>QueueDirectories</key> <array> <string>/usr/lib/cron/tabs</string> </array> <key>EnableTransactions</key> <true/></dict></plist>注意里面有个keepAlive的条件是 /etc/crontab 是否存在: <key>KeepAlive</key> <dict> <key>PathState</key> <dict> <key>/etc/crontab</key> <true/> </dict> </dict>查看 /etc/crontab 是否存在➜ ~ ll /etc/crontabls: /etc/crontab: No such file or directory查看得知,该文件不存在,创建该文件。➜ ~ sudo touch /etc/crontab最终,就可以成功执行了。需要注意的是,sh脚本中的路径,最好使用绝对路径,否则脚本很可能将无法正确执行 ...

December 24, 2018 · 1 min · jiezi