Monkeyrunner throwing "ShellCommandUnrespo​nsiveException" - any work around? - adb

I am facing some issues in device.shell('ping -c 2 192.168.1.1') inside a monkeyrunner script.
Its throwing
ShellCommandUnrespo‌​nsiveException
[main] [com.android.chimpchat.adb.AdbChimpDevice]com.android.ddmlib.ShellCommandUnrespo‌​nsiveException
while (count<1000) :
device.shell('dmesg -c')
print '****swithing OFF wifi in loop NO-',count
device.touch(400,155,MonkeyDevice.DOWN_AND_UP)
time.sleep(10)
print '****switching ON wifi in loop NO-',count
device.touch(400,155,MonkeyDevice.DOWN_AND_UP)
time.sleep(25)
fd=open('pingstats.txt','a+b')
fd.write('***Loop-%i \n************\n%s\n****************\n' % (int(count),ping))
ping = device.shell('ping -c 2 192.168.1.1')
status=re.search('unreachable',ping)
if status:
dmesg=device.shell('dmesg')
fd.write(logcat)
fd.close()
count = count + 1
Please see above script. How can I fix this?

your ping waits to long
add a -t
start with -t 1

Just add -t . An example below works perfectly !
device.shell('pm enable packageName -t 15')

Related

shell mock --define from array: ERROR: Bad option for '--define' ("dist). Use --define 'macro expr'

I am currently writing a script which should make it more easy for me to build some RPMs using mock.
The plan is to make it possible to add values for the mock (and therefor rpmbuild) --define parameter.
The error I get if I add such a define value is
ERROR: Bad option for '--define' ("dist). Use --define 'macro expr'
When I execute the script with as simple as ./test.sh --define "dist .el7" the "debug" output is as follows:
/usr/bin/mock --init -r epel-7-x86_64 --define "dist .el7"
If I copy this and execute it in the shell directly it is actually working. Does anybody have an idea why this is the case?
My script can be cut down to the following:
#!/bin/sh
set -e
set -u
set -o pipefail
C_MOCK="/usr/bin/mock"
MOCK_DEFINES=()
_add_mock_define() {
#_check_parameters_count_strict 1 ${#}
local MOCK_DEFINE="${1}"
MOCK_DEFINES+=("${MOCK_DEFINE}")
}
_print_mock_defines_parameter() {
if [ ${#MOCK_DEFINES[#]} -eq 0 ]; then
return 0
fi
printf -- "--define \"%s\" " "${MOCK_DEFINES[#]}"
}
_mock_init() {
local MOCK_DEFINES_STRING="$(_print_mock_defines_parameter)"
local MOCK_PARAMS="--init"
MOCK_PARAMS="${MOCK_PARAMS} -r epel-7-x86_64"
[ ! "${#MOCK_DEFINES_STRING}" -eq 0 ] && MOCK_PARAMS="${MOCK_PARAMS} ${MOCK_DEFINES_STRING}"
echo "${C_MOCK} ${MOCK_PARAMS}"
${C_MOCK} ${MOCK_PARAMS}
local RC=${?}
if [ ${RC} -ne 0 ]; then
_exit_error "Error while mock initializing ..." ${RC}
fi
}
while (( ${#} )); do
case "${1}" in
-s|--define)
shift 1
_add_mock_define "${1}"
;;
esac
shift 1
done
_mock_init
exit 0
After asking this question a coworker I was pointed to this question on unix stackexchange: Unix Stackexchange question
The way this problem was solved can be broken down to following lines:
DEFINES=()
DEFINES+=(--define "dist .el7")
DEFINES+=(--define "foo bar")
/usr/bin/mock --init -r epel-7-x86_64 "${DEFINES[#]}"
Just in case somebody else stumbles upon this kind of issue.

capistrano run_locally wrong number of arguments

after :finishing, :send_rollbar_notice do
on roles(:web) do
access_token = 'special_key_goes_here'
environment = fetch(:environment)
local_username = `whoami`.strip
revision = `git log -n 1 --pretty=format:"%H"`
curl_command = %{curl https://api.rollbar.com/api/1/deploy/ -F 'access_token=#{access_token}' -F 'environment=#{environment}' -F 'revision=#{revision}' -F 'local_username=#{local_username}'}
puts curl_command
output = run_locally "#{curl_command}"
puts output
end
end
Can someone help me figure out why I'm getting the follow error after I run the cap deploy command?
ArgumentError: wrong number of arguments (1 for 0)
Any help is much appreciated!
Got it! :)
Replace on roles(:web) do with run_locally do

makefile missing separator in Mac OS X

I have a makefile which gives the following error in OS X, I will be very grateful if someone have an idea about why is getting this error:
./../../../..//Source//templates/gcc/Makefile.posix:15: *** missing separator. Stop.
Here is the makefile:
GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-4_8-2014q3
GNU_VERSION := 4.8.3
GNU_PREFIX := arm-none-eabi
GDB_PORT_NUMBER := 9992
FLASH_START_ADDR = $(shell $(OBJDUMP) -h $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out -j .text | grep .text | awk '{print $$4}')
JLINK_OPTS = -device nrf51822 -if swd -speed 4000
JLINK_GDB_OPTS = -noir
JLINK = JLinkExe $(JLINK_OPTS)
JLINKD_GDB = JLinkGDBServer $(JLINK_GDB_OPTS)
flash-jlink: flash.jlink
$(JLINK) flash.jlink
flash.jlink:
printf "loadbin $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin $(FLASH_START_ADDR)\nr\ng\nexit\n" > flash.jlink
erase-all: erase-all.jlink
$(JLINK) erase-all.jlink
erase-all.jlink:
# Write to NVMC to enable erase, do erase all, wait for completion. reset
printf "w4 4001e504 2\nw4 4001e50c 1\nsleep 100\nr\nexit\n" > erase-all.jlink
run-debug:
$(JLINKD_GDB) $(JLINK_OPTS) $(JLINK_GDB_OPTS) -port $(GDB_PORT_NUMBER)
.PHONY: flash-jlink flash.jlink erase-all erase-all.jlink run-debug
TAB character in Brackets editor were replaced by 4 spaces (sp sp sp sp). Changing to other editor (TextMate) solved the problem
I was using VIM (on MacOS) and found that 'expandtab' was the issue when parsing Makefiles. If set, it turns your tab into 4 spaces. (so i commented it out)
" expand tabs into spaces
"set expandtab
On Mac OS X and SublimeText 3 I had to change the indentation from spaces to tabs to solve the same problem '"Makefile:4: *** missing separator. Stop."'.
So I did the following on SublimeText 3 in the lower left corner to fix the error:
Click on Spaces:4 > Tab Width: 4
Click on Spaces: 4 > Convert Indentation to Tab

Looping an array index into a screen session [duplicate]

This question already has answers here:
Bash array as argument inside of screen
(2 answers)
Closed 8 years ago.
#!/bin/bash
IFS=$'\n'
fortune_lines=($(fortune | fold -w 30))
Screen_Session=$"{mainscreen}"
Screen_OneLiner=$(screen -p 0 -S ${Screen_Session} -X stuff "`printf "say ${fortune_lines[#]}\r"`")
for var in "${Screen_OneLiner[#]}"
do
echo -e "${var}"
done
The above script only prints out line 1 one of
IFS=$'\n'
fortune_lines=($(fortune | fold -w 30))
Instead of cycling through the whole index of "fortune_lines" Not sure how to make this work.
Any ideas?
FYI
I am only using
echo -e
to troubleshoot this script.
#!/bin/bash
#OLDIFS=$IFS
IFS=$'\r'
fortune_lines=($(cat /etc/passwd | fold -w 30))
#Screen_Session=$"{mainscreen}"
Screen_Session=`screen -ls|grep "\."|grep "("|awk '{print $1}'`
Screen_OneLiner=$(screen -p 0 -S ${Screen_Session} -X stuff "`printf "say ${fortune_lines[#]}\r"`")
#IFS=$OLDIFS;
for var in "${Screen_OneLiner[#]}"
do
echo -e "${var}"
done
works fine for me I changed IFS to \r and it pumped out /etc/passwd where as with \n it only printed 1st line

Error while issuing ping command inside monkeyrunner script

i am facing some issues in device.shell('ping -c 2 192.168.1.1') inside a monkeyrunner script.
Its throwing below error:-
120202 20:12:17.192:S [main] [com.android.chimpchat.adb.AdbChimpDevice] Error executing command: ping -c 2 192.168.1.1
while (count<1000) :
device.shell('dmesg -c')
print '****swithing OFF wifi in loop NO-',count
device.touch(400,155,MonkeyDevice.DOWN_AND_UP)
time.sleep(10)
print '****switching ON wifi in loop NO-',count
device.touch(400,155,MonkeyDevice.DOWN_AND_UP)
time.sleep(25)
fd=open('pingstats.txt','a+b')
fd.write('***Loop-%i \n************\n%s\n****************\n' % (int(count),ping))
ping = device.shell('ping -c 2 192.168.1.1')
status=re.search('unreachable',ping)
if status:
dmesg=device.shell('dmesg')
fd.write(logcat)
fd.close()
count = count + 1
please see above script...
Someone please help....

Resources