I'm trying to write a bash script in Ubuntu to install an app on an android emulator, send random commands to the app using 'monkey' and capture all the data with tcpdump. Code:
#!/bin/bash
#store all apks files in array
shopt -s nullglob
packageArray=(*.apk)
function getPackageName()
{
myResult= aapt dump badging $1 | grep package | awk '{print $2}' | sed s/name=//g | sed s/\'//g
}
#loop through array installing, testing and capturing data, and uninstalling
for i in "${packageArray[@]}";
do
:
myResult=$(getPackageName "$i")
echo "------------------INSTALLING-----------------"
sudo adb install $i
echo "*****************INSTALLED****************************"
echo "*****************TESTING****************************"
#-------THESE COMMANDS ARE THE TROUBLE-------
(sudo -i xterm -e "tcpdump src 10.0.2.11 -vvv > /home/seed/Documents/autoTcpLogs/$myResult.pcap" &
sudo -i xterm -e "adb shell monkey -p $myResult -v 500")
echo "------------------DONE TESTING-----------------"
sudo adb uninstall $myResult
echo "*****************PACKAGE UNINSTALLED****************************"
done
The Problem: I need a good way for tcpdump to close once monkey has completed sending the 500 random commands. I've tried using the KILL command in a few different ways, but it doesn't seem to do the trick.