배쉬 스크립트. 원숭이 테스트 도구 만들기 [AntergOS]

배쉬 스크립트. 원숭이 테스트 도구 만들기 [AntergOS]

다른 bash 스크립트를 실행하고 자체적으로 재귀적으로 실행되는 bash 스크립트를 실행할 때 이 오류가 발생합니다.

내가 사용하는 스크립트에서는 xdotool내가 사용하는 모든 스크립트에서 카운터가 생성되고 호출되며 $RANDOM( $RANDOMwhile-loop에서 호출되는 파일도 최대 20번 반복) 모든 명령은 echo 'command'를 사용하여 리플로우되어 파일에 저장되도록 지시됩니다.

나에게 다음과 같은 오류가 발생합니다.

./somescript.sh: fork: Cannot allocate memory

운영 체제 정보: Antergos 64비트 + Openbox + 8GB RAM

열기: qtcreator, lxterminal, 내 qt 애플리케이션(100Mb) 이제 로그 파일의 크기는 3,5 МіB입니다. 내 거 ulimit -a:

[user@workstation MonkeyClicker]$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31856
max locked memory       (kbytes, -l) 1024
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31856
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

run.sh스크립트:

#!/bin/bash

if [ -z $1 ]
then
        echo ' '
        echo '***************MONKEY TESTING TOOL HELP***************'
        echo ' '
        echo 'command: run.sh [start delay]'
        echo '[start delay] - means that you have X seconds to start your program'
        echo 'for example : run.sh 3s 0.1s'
        echo ' '
else
        mkdir -p logScript
        ./monkeyTestingTool.sh $1 > $PWD/logScript/script.sh
fi

monkeyTestingTool.sh스크립트:

!/bin/bash

if [ $1 ]
then
        echo '#Started in:' $date
        echo '#MONKEY TESTING START, BE CAREFUL!'
        echo '#You have' $1 'seconds to open your app for testing ...'
        sleep $1
fi

echo $(xdotool getmouselocation --shell)
echo 'xdotool mousemove --sync $X $Y'

RANGE=7
CHOOSE=$RANDOM
let "CHOOSE %= $RANGE"

case $CHOOSE in
0) sh ./move.sh
;;
1) sh ./callContextMenu.sh
;;
2) sh ./typeRandom.sh
;;
3) xdotool click 1 #this is leftMouseClick
;;
4) sh ./keyPressing.sh
;;
5) sh ./move.sh
;;
6) sh ./dragDrop.sh
#*) TODO: drag and drop
esac

./monkeyTestingTool.sh

예를 들어 내 callContextMenu.sh스크립트는 다음과 같습니다.

#!/bin/bash

echo $(xdotool getmouselocation --shell)
echo 'xdotool mousemove --sync $X $Y'

echo 'xdotool click 3'
xdotool click 3

LASTKEY=0
RANGESTEPS=20
STEPS=$RANDOM
let "STEPS %= $RANGESTEPS"

while [ $STEPS != 0 ]; do
        RANGE=5
        CHOOSE=$RANDOM
        let "CHOOSE %= $RANGE"
        let STEPS=STEPS-1
        LASTKEY=$CHOOSE
        case $CHOOSE in
        0) xdotool key Up
        echo 'xdotool key Up'
        ;;
        1) xdotool key Left
        echo 'xdotool key Left'
        ;;
        2) xdotool key Down
        echo 'xdotool key Down'
        ;;
        3) if [ $STEPS == 1 ]
        then
                echo 'xdotool key Return'
                xdotool key Return
        fi
        ;;
        4) xdotool key Right
        echo 'xdotool key Right'
        ;;
        esac
done

if [ $LASTKEY != 3 ]
then
        echo 'xdotool key Return'
        xdotool key Return
else
        echo 'xdotool key Down'
        echo 'xdotool Return'
        xdotool key Down
        xdotool key Return
fi

답변1

마지막 회선 monkeyTestingTool.sh호출 자체

./monkeyTestingTool.sh

이는 곧 수백 개의 프로그램 복사본을 실행하게 될 것임을 의미합니다.

스크립트를 다시 실행하려면 마지막 줄을 수행하십시오.

exec ./monkeyTestingTool.sh

또는 모든 것을 while다음과 유사한 루프에 넣습니다.

while [ 1 ]
do
  CHOOSE=$RANDOM
  let "CHOOSE %= $RANGE"

  case $CHOOSE in
  0) sh ./move.sh
  ;;
  ....
  esac
done

관련 정보