본문 바로가기

서버 | OS/Linux - Shell Script

(5)
Send e-mail with attachment in shell environment. Tested(target) OSs : Ubuntu Arch Linux Required packages : msmtp (simple mail client that can support external smtp like Gmail, Naver etc.) mutt (needs for file attachment) 1. Install package Ubuntu : apt-get install -y msmtp mutt Arch Linux : pacman -S msmtp mutt 2. Prepare shell environment create a "~/.msmtprc" file for msmtp cat ~/.msmtprc # Set default values for all following accounts. def..
쉘스크립트의 명령행 인자를 파싱하는 방법 일반적으로 쉘 스크립트를 만들 때 플래그 인자 값을 전달받아 처리하는 루틴을 구현하고자 하는 경우 getopt 나 getopts를 이용하는 경우가 많다. 여기서는, 또 다른 방법으로 for loop 와 case 를 이용해서 플래그 인자 값을 분류하고 처리하는 루틴을 구현하는 방법으로써 쉘 스크립트 개발에 getopt 나 getopts 에 친숙하지 않은 개발자에게 손쉽게 응용 가능할 것이라 생각되는 루틴이어서 발췌한다. ### pivpn.io 의 설치 스크립트로 부터 발췌한 파싱 방법은 아래와 같음. # Check arguments for the undocumented flags for ((i = 1; i
쉘 환경변수에 행 단위로 텍스트 저장/불러오기. 쉘의 배열을 이용해 여러행(multiple-line)을 파싱할 때 활용하는 방법을 안내합니다. # "ip -o link" 명령 실행 결과를 행 단위로 VARR 변수에 넣는 예 IFS=$'\r\n' GLOBIGNORE='*' command eval 'VARR=($(ip -o link))' # 배열의 정보를 행 단위로 출력 : echo ${VARR[0]} echo ${VARR[1]}
한줄로 tar + gzip 압축 진행상태 모니터링 Compress tar cf - -P | pv -s $(du -sb | awk '{print $1}') | gzip > where: is the root-mounted (i.e. starts with /) path to the files is the output tarball to create Decompress pv | tar -xvzf - -C where: is the path to the tarball to extract is the directory to extract the tarball to Source : https://gist.github.com/Kautenja/tar-progress.md
Faster bulk(directory) copy than cp, and watch progress tar cf - . | ( cd /target-dir/ ; tar xf - ) yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install --disablerepo="*" --enablerepo="epel" pv tar cf - . | pv | ( cd /target-dir/ ; tar xf - )