wintertreey 님의 블로그
Shell Script 본문
https://opentutorials.org/course/2598/14204
쉘 스크립트 - 생활코딩
강의소개 쉘을 통해서 명령을 실행시키는 작업을 한번에 실행할 수 있는 방법을 알아봅니다. 수업 강의 1 - Shell script 소개 강의 2 - Shell Script 사례 예제 #!/bin/bash if ! [ -d bak ]; then mkdir bak fi cp *.lo
opentutorials.org
Shell Script
반복적인 작업을 자동화하고 시스템 관리를 효율적으로 수행하는데 쓰임.
예를 들어 큰 시스템의 로그를 주기적으로 삭제하는작업.
ex. 3개월 지난 로그 지우기. 로그 백업하기.
mkdir script
cd script/
ll
touch a.log b.log c.log
ll
vi backup.sh
쉘스크립트 내용
만약 bak이라는 이름의 디렉토리가 없다면, 생성해줘.
현재 경로에 있는 .log로 끝나는 파일들을 bak 디렉토리로 복사해줘.
#!/bin/bash
if ! [ -d bak ]; then
mkdir bak
fi
cp *.log bak
#!/bin/bash
쉘스크립트 작성시 반드시 상단에 적어주고 시작해야한다.
띄어쓰기 꼭 유의하자.
한번 잘 만들어졌는지 확인해보자.
the difference b/w shell and bash
Shell
사용자와 운영체제 사이의 인터페이스.
사용자로부터 명령을 받아서 운영체제에게 전달하고, 그 결과를 사용자에게 다시 보여줌.
Bash
shell의 종류 중 하나.
현재 내가 연습하는 서버는 bash shell을 사용하고있음.
apache tomcat startup.sh
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
# Better OS/400 detection: see Bugzilla 31132
os400=false
case "`uname`" in
OS400*) os400=true;;
esac
# resolve links - $0 may be a softlink
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done
PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh
# Check that target executable exists
if $os400; then
# -x will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
eval
else
if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
echo "Cannot find $PRGDIR/$EXECUTABLE"
echo "The file is absent or does not have execute permission"
echo "This file is needed to run this program"
exit 1
fi
fi
exec "$PRGDIR"/"$EXECUTABLE" start "$@"
쉘 스크립트 작성해보기
vi trial.sh
#!/bin/bash
name="winter"
date=250529
echo $name
echo "I wrote this script ${date}."
printf "== the end =="
https://velog.io/@ttanggin/ShellBash
[Unix] Shell과 Bash
모르고 쓰던 Shell과 Bash가 무엇인지 알아보자!
velog.io
https://github.com/apache/tomcat/blob/main/bin/startup.sh
tomcat/bin/startup.sh at main · apache/tomcat
Apache Tomcat. Contribute to apache/tomcat development by creating an account on GitHub.
github.com
https://probe29.tistory.com/47
쉘(bash Shell) 스크립트 기본 문법, 실제 예제(백업하기, 로그 파일 정리하기)
# 쉘 스크립트 서버 작업 자동화 및 운영(DevOps)을 위해 기본적으로 익혀둘 필요가 있다. 쉘 명령어를 기본으로 하되, 몇 가지 문법이 추가된 형태 시스템 프로그래밍에서 꼭 익히는 내용 중 하나
probe29.tistory.com
'리눅스' 카테고리의 다른 글
리눅스에서 정확한 이름을 입력하기 어려운 디렉토리나 파일 삭제하는 방법 (1) | 2025.06.05 |
---|---|
디렉토리 구조 (0) | 2025.06.04 |
Shell and Kernel (1) | 2025.05.26 |
IO Redirection : (0) | 2025.05.23 |
CLI. ;. grep. pipeline (0) | 2025.05.22 |