blob: 808ac0effde66f315ca5baf181d5566afe586031 [file] [log] [blame]
Boyuan Yan1c27bc72019-02-15 19:22:19 +00001#!/bin/bash
2
3# This script is used to execute some checking commands in period to confirm whether specific requirement is satisfied.
4# $1 - the command to be executed in this script, whose parameter splitter is +, but ont space. This command could use |, &&, || to concatenate multiple shell commands.
5# $2 - Optional. If exists, it means the output (Note: not returned value) of $1 should equals $2.
6
7cmd=${1//'+'/' '}
8if [ $# == 1 ]; then
9 for i in {1..60}; do
10 eval ${cmd}
11 rtn=$?
12 if [[ ${rtn} -ne 0 ]]
13 then
14 echo "$i-th execution returns $rtn"
15 sleep 3
16 else
17 exit 0
18 fi
19 done
20elif [ $# == 2 ]; then
21 for i in {1..60}; do
22 out=`eval ${cmd}`
23 rtn=$?
24 if [[ ${rtn} -ne 0 || "$out" != $2 ]]; then
25 echo "$i-th execution fails"
26 sleep 3
27 else
28 exit 0
29 fi
30 done
31fi