๊ฐ„๋‹จํ•œ shell script ์‹คํ–‰ ๋ฐฉ๋ฒ• (feat: IntelliJ)

2022. 12. 23. 22:14ใ†๐Ÿ“” TIL

๊ธฐ์กด ๋ช…๋ น์–ด ์ž…๋ ฅ ๋ฐฉ์‹

๋™์‹œ์„ฑ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด curl (Client URL) ์„ ์—ฐ์†์œผ๋กœ ํ˜ธ์ถœํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

ํ„ฐ๋ฏธ๋„ ์ฝ˜์†”์—์„œ ์•„๋ž˜์ฒ˜๋Ÿผ &๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด curl ์š”์ฒญ์„ ๋™์‹œ์— ์—ฌ๋Ÿฌ๋ฒˆ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

$ curl 'url' & curl 'url' & curl 'url' & curl 'url' & curl 'url'

๋งค๋ฒˆ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ธด ๊ท€์ฐฎ์•„์„œ shell script ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค.

์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰์ค‘์ด๋‹ˆ IntelliJ ์˜ src ํด๋” ํ•˜์œ„์— shell script ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

shell script ์ž…๋ ฅ ๋ฐฉ์‹

run.sh ๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ํŒŒ์ผ์„ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

 

run.sh

#!/bin/sh
curl "http://localhost:8080/human/decrease?name=hoo&money=1000" &
curl "http://localhost:8080/human/decrease?name=hoo&money=1000" &
curl "http://localhost:8080/human/decrease?name=hoo&money=1000" &
curl "http://localhost:8080/human/decrease?name=hoo&money=1000" &
curl "http://localhost:8080/human/decrease?name=hoo&money=1000"

#!/bin/sh๋ฅผ ๊ธฐ์žฌํ•ด ์ค๋‹ˆ๋‹ค. ์‹œ์Šคํ…œ ์‰˜ ์‚ฌ์šฉ์„ ์„ ์–ธํ•˜๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

 

๊ฐ„๋‹จํ•œ ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์œผ๋‹ˆ, ํ„ฐ๋ฏธ๋„์—์„œ ํ•ด๋‹น ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

$ ./run.sh

zsh: permission denied: ./run.sh ๊ฒฝ๊ณ ๋ฌธ์ด ์ถœ๋ ฅ๋˜๋ฉด์„œ ์‹คํ–‰์ด ์•ˆ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

chmod ๋ช…๋ น์–ด๋กœ ํ•ด๋‹น ํŒŒ์ผ์˜ ์‹คํ–‰ ๊ถŒํ•œ์„ ํ’€์–ด์ค์‹œ๋‹ค.

$ chmod 744 run.sh

ํŒŒ์ผ ์†Œ์œ ์ž์— ๋Œ€ํ•ด ๋ชจ๋“  ๊ถŒํ•œ(read, write, execute)์„ ํ—ˆ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ ๋‹ค์‹œ ./run.sh ๋ช…๋ น์–ด๋ฅผ ํ„ฐ๋ฏธ๋„์— ์ž…๋ ฅํ•˜๋ฉด run.sh ํŒŒ์ผ์— ์ž‘์„ฑํ•œ ์Šคํฌ๋ฆฝํŠธ์˜ ๋‚ด์šฉ์ด ์ž๋™ ์‹คํ–‰ ๋ฉ๋‹ˆ๋‹ค.