[Linux] shell script 활용
구성
./script
test1.sh
test2.sh
test3.sh
./service.conf
service1.conf
service2.conf
service3.conf
아래 /etc/yum.conf 내용 복사해서 service1.conf service2.conf 사용
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
test1.sh으로 service1.conf 특정라인 한줄 변경
service1.conf
6번째 라인 주석 처리
7번째 라인 obsolstes=1 >> obsoletes=2
15번째 라인 주석 해제
구문 : sed [-option] '[subcommand]' [file]
sed는 기본적으로 출력 명령어 이기때문에 -i 옵션을 통해서 수정만하고 출력하지않겠다.
subcommand "s" 치환!!
6s > 6번째 줄 exactarch를 #exactarch로 치환겠다.
7s > 7번째 줄 1을 2로 치환겠다.
15s > 15번째 줄 # This 를 This로 치환하겠다.
test2.sh으로 service2.conf 특정라인 아래 여러줄 생성
12번째 줄 밑에
systemctl enable kibana
systemctl start kibana 추가
subcommand "a\" 추가!!(백슬래시)
12a\ > 12번 째 줄 '아래' (13번째 줄에) systemctl enable kibana 추가하겠다.
13a\ > 13번 째 줄 '아래' (14번째 줄에) systemctl start kibana 추가하겠다.
test3.sh으로 service3.conf 새로운 파일 생성
생성할 service3.conf 내용
server {
listen 80;
server _name kgitbank.com;
auth_basic Restricted Access;
auth_basic_user_file /etc/nginx/.kibana-user;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host;
proxy_cache_bypass;
}
}
리다이렉션 기호 >>
echo 명령어로 출력되는 내용을 해당 파일에 '추가'입력하고 저장하겠다.
만약 > (하나만 쓴다면)
echo 명령어로 출력되는 내용을 해당 파일에 '덮어쓰고' 저장하겠다.