(2) #!/bin/bash

2021. 3. 22. 12:22개발공부/Linux


#!/bin/bash


정의 : 스크립트문을 어떻게 해석할 지 커맨드를 지정해주는 코멘트 라인입니다. 스크립트 파일 첫줄에 쓰입니다.

(In simple words, the she-bang at the head of the script tells the system that this file is a set of commands to be fed to the command interpreter indicated)


예시 : 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
REPOSITORY=/home/ubuntu/salle/salle
 
cd $REPOSITORY
 
echo "> Git pull"
 
git pull
 
echo  "> 프로젝트 Build 시작"
 
./mvnw clean package
 
echo "> 현재 구동중인 애플리케이션 pid 확인"
 
CURRENT_PID=$(pgrep -f salle)
 
echo "$CURRENT_PID"
 
if [ -z $CURRENT_PID ]; then
        echo ">현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다"
 
else
        echo "> kill -2 $CURRENT_PID;"
        kill  $CURRENT_PID
        sleep 5
        fi
echo "$CURRENT_PID HUP 재확인"
if [ -z $CURRENT_PID ]; then
        echo ">현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다"
else
        echo ">kill -2 $ $CURRENT_PID"
        kill $CURRENT_PID
        sleep 5
        fi
echo "> 새 애플리케이션 배포"
JAR_NAME=test-0.0.1-SNAPSHOT.jar
 
cd target
cs

 

참고자료 : Sanjay Mishra - What exactly is (#!/bin/bash)

'개발공부 > Linux' 카테고리의 다른 글

[Ubuntu설치] 깡통 데스크탑 Ubuntu 설치 및 MariaDB, Redis 설정  (0) 2021.09.11
(1) &  (0) 2021.03.12
Linux - 특수권한(SetUid, Sticky Bit)  (0) 2020.07.01