쉘스크립트 IF문 조건식

쉘스크립트에서 자주사용하지만 매번 헷갈리는 IF문 조건식입니다.

문자열체크

[ stringName ] – 문자열이 널(NULL)인지 체크, Null이 아니면 참
[ -n stringName ] – 문자열의 사이즈가 0 이상인지 체크, 0 이상이면 참
[ -z stringName ] – 문자열의 사이즈가 0 인지 체크, 0이면 참
[ stringNameA = stringNameB ] – A문자열과 B문자열이 같은지 체크, 같으면 참
[ stringNameA != stringNameB ] – A문자열과 B문자열이 다른지 체크, 다르면 참

 

숫자 대소 관계 체크

[ intA -ge 100 ] – 숫자 A가 100보다 크거나 같은지 체크, 100 이상이면 참
[ intA -gt 100 ] – 숫자 A가 100보다 큰지 체크, 100이 넘으면 참
[ intA -le 100 ] – 숫자 A가 100보다 작거나 같은지 체크, 100 이하이면 참
[ intA -lt 100 ] – 숫자 A가 100보자 작은지 체크, 100 미만이면 참

 

파일 체크

[ -r filename ] – 해당 파일이 읽기 가능한지 체크
[ -w filename ] – 해당 파일이 쓰기 가능한지 체크
[ -x filename ] – 해당 파일이 실행 가능한지 체크
[ -s filename ] – 해당 파일의 사이즈가 제로 이상인지 체크
[ -d filename ] – 해당 파일이 디렉토리 파일인지 체크
[ -f filename ] – 해당 파일이 보통 파일인지 체크
[ -h filename ] – 해당 파일이 링크 파일인지 체크

 

조건문의 결합

[ 조건문A -a 조건문B ] – 조건문 A와 B가 모두 참인지 체크, -a는 AND
[ 조건문A -o 조건문B ] – 조건문 A와 B중 참이 하나라도 있는지 체크, -o는 OR

Facebook API ipv6 Network is unreachable

LINUX에서 FACEBOOK API 연동시 아래와 같은 오류가 발생했습니다

Failed to connect to 2a03:2880:2050:1f08:face:b00c:0:1: Network is unreachable

 이 오류는 ipv4 설정이 되있는 서버에서 ipv6가 활성화 되면서 해당 도메인의 ipv6 주소로 접근을 하려고하나, 해당 서버의 ipv6 네트워크가 정상적이지 않기 때문에 발생하는 오류입니다.

 이 문제는 해당서버의 ipv6를 disable 해주므로써 해결이 가능합니다.

vi /etc/sysctl.conf
# disable ipv6
net.ipv6.conf.all.disable_ipv6=1sysctl -p (재부팅 안하고 적용)

위와 같이 설정후 재부팅하면 적용이 가능하고, 혹시라도 안되면 아래의 사이트에서 다른 방법을 찾아봐야할 것 같습니다.

 

http://wiki.centos.org/FAQ/CentOS5#head-47912ebdae3b5ac10ff76053ef057c366b421dc4

 

9. How do I disable IPv6?

  • Edit /etc/sysconfig/network and set “NETWORKING_IPV6” to “no”
  • For 5.4 and later, replace in /etc/modprobe.conf

 

alias ipv6 off

by

options ipv6 disable=1

Alternative (which might be easier and works on any release with /etc/modprobe.d):

# touch /etc/modprobe.d/disable-ipv6.conf
# echo "install ipv6 /bin/true" >> /etc/modprobe.d/disable-ipv6.conf
  • For CentOS 5.3 or older, add the following to /etc/modprobe.conf :

 

alias ipv6 off
alias net-pf-10 off
  • Run /sbin/chkconfig ip6tables off to disable the IPv6 firewall
  • Reboot the system

<!> With the 5.4 update symbol/ipv6 module dependency capabilities have been introduced; therefore, if IPv6 has been previously disabled as above an upgrade to the bonding driver in 5.4 will result in the bonding kernel module failing to load. For the module to load properly use instead:

# touch /etc/modprobe.d/disable-ipv6.conf
# echo "options ipv6 disable=1" >> /etc/modprobe.d/disable-ipv6.conf

<!> <!> Upstream employee Daniel Walsh recommends not disabling the ipv6 module but adding the following to /etc/sysctl.conf:

net.ipv6.conf.all.disable_ipv6 = 1