반응형
Shell script를 작성하다보면, Random 숫자가 필요한 경우가 있다.
아래 예제 스크립트처럼 $RANDOM 변수를 사용하면, 매번 새로운 random integer를 구할 수 있다.
간단한 Example Script
#!/usr/local/bin/bash for i in `seq 3` do myrand=$RANDOM echo "Original random number: $myrand" mynum=$(expr $myrand / 1000) echo "Devided number: $mynum" done
Random 초 만큼 쉬면서 CURL 명령을 반복 수행하는 Example Script
아래 예제는 실제로 ISTIO의 BookInfo 예제를 돌릴 때, 내가 종종 이용하는 Script이다.
#!/bin/bash test_url="http://node-40.hub.cncf/productpage" for i in $(seq 1 99999) do curl -s -o /dev/null $test_url -: \ -s -o /dev/null http://grafana.hub.cncf/?orgId=1 -: \ -s -o /dev/null http://tracing.hub.cncf/jaeger/search myrand=$RANDOM mysleeptime=$(expr $myrand % 7) printf "Run count: %d (Sleep: %d seconds)\r" $i $mysleeptime sleep $mysleeptime done
'Shell Script' 카테고리의 다른 글
문자열에서 따옴표 떼어내기(제거하기) (0) | 2022.01.22 |
---|---|
문자열 분리, 특정 컬럼 출력하는 명령 (String split, delimit) - cut, awk, print 명령 (0) | 2021.11.11 |
grep command with invert-match option (0) | 2021.10.06 |
Man page dump하기 (0) | 2021.07.15 |
for loop 예쁘게 출력하기 (0) | 2021.07.13 |