blob: 5dee9746a123cf331569f78a1af8f9f31ca34f9f [file] [log] [blame]
Boyuan Yaned2ea3572019-04-02 15:38:42 -07001#!/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 out="${out// /}"
25 if [[ ${rtn} -ne 0 || "$out" != $2 ]]; then
26 echo "$i-th execution fails"
27 sleep 3
28 else
29 exit 0
30 fi
31 done
32fi