Error while issuing ping command inside monkeyrunner script - adb

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....

Related

How does bash redirection work under the hood?

I'm trying to reimplement the bash redirection and execution part for a small project, but I don't figure out how it works.
For example :
cat <<limit <<limit <<limit
I don't know why all of them executed even an error parse show up
bash-3.2$ <<lim | <<lim2 <><><
bash: syntax error near unexpected token `<>'
> lim
> lim2
bash-3.2$
in other case they didn't execute
bash-3.2$ <<lim | <<lim2 <><>< <<lim3
bash: syntax error near unexpected token `<>'
> lim
> lim2
bash-3.2$

expect returns error "spawn id exp5 not open" running c program

I'am running some test on a program with the following code:
set timeout -1
set filename "test"
set programName "./library"
spawn rm -f $filename.db $filename.ind
spawn ./$programName first_fit $filename
expect "Type command and argument/s."
expect "exit"
The program output is the following:
Type command and argument/s.
exit
both lines are written using printf and the next line that executes is fgets();
expects outputs the following error:
expect: spawn id exp5 not open
while executing
"expect "exit""
(file "add_data_test.sh" line 16)

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

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

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')

Resources