Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 1 | #!/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 | |
| 7 | cmd=${1//'+'/' '} |
| 8 | if [ $# == 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 |
| 20 | elif [ $# == 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 |
| 31 | fi |