Hong의 모든 글

쉘스크립트 IF문 – shell script if elif else

쉘스크립트(shell script)로도 If elif 를 사용할 수 있습니다.

가끔 쓰기 때문에 기억이 잘 나지 않아서 말이지요.

그리고 case 구문을 지원하기 때문에 여러 조건을 확인해야 하는 것도 가능하지만

case문은 가독성이 너무 떨어지기 때문에 거의 사용하지 않습니다.

어쨌든 shell script (bash 기준)에서 if, elif, else 구문은 이렇게 씁니다.

#!/bin/bash

a="1"
if [[ $a == "1" ]]; then
    echo "a is 1"
elif [[ $a == "2" ]]; then
    echo "a is 2"
elif [[ $a == "3" ]]; then
    echo "a is 3"
elif [[ $a == "4" ]]; then
    echo "a is 4"
else
    echo "a is not 1, 2, 3, or 4"
fi

쉘스크립트 7일전 날짜 가져오기 – Shell script get date of 7 days ago

쉘스크립트에서 7일전 (1주일전) 날짜를 가져오는 방법입니다.

별로 어렵지 않은데 막상 쓰려면 기억이 잘나지 않죠.

아래와 같이 하면 됩니다.

date -d "7 days ago" +"%Y-%m-%d"

7일전부터 어제까지 7일간의 구간을 계산하려면 아래와 같이 하면 됩니다.

yesterday=$(date -d "1 days ago" +"%Y-%m-%d")  # 어제 날짜
ago7days=$(date -d "7 days ago" +"%Y-%m-%d")  # 7일전
echo "yesterday:$yesterday, ago7days:$ago7days"

cURL curl: (77) error setting certificate verify locations 에러

리눅스 curl 코맨드로 https url을 당겨올 때 에러가 날때가 있습니다.

curl: (77) error setting certificate verify locations:
  CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none

원인은 /etc/pki/tls/certs/ca-bundle.crt 가 없기 때문입니다.

다음과 같이 하면 처리됩니다.

sudo mkdir -p /etc/pki/tls/certs
sudo cp /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt