본문 바로가기

스크립트

리눅스에서 운영체제와 GCC 버전을 체크하는 스크립트

반응형

리눅스에서 운영체제와 GCC 버전을 체크하는 스크립트

check_system.sh 스크립트 작성

vim check_system.sh
#!/bin/bash

# 운영체제 버전 체크
if [ -f /etc/os-release ]; then
    source /etc/os-release
    OS=$ID
elif [ -f /etc/centos-release ]; then
    OS="centos"
else
    echo "지원하지 않는 운영체제입니다."
    exit 1
fi

# GCC 버전 및 관련 패키지 체크
if [ "$OS" == "centos" ]; then
    BIT=$(getconf LONG_BIT)
    GCC_VERSION=$(gcc --version | head -n1 | awk '{print $3}')
    GCC_CXX_VERSION=$(g++ --version | head -n1 | awk '{print $3}')
    LIBTOOL_VERSION=$(libtool --version | head -n1 | awk '{print $4}')
    AUTOCONF_VERSION=$(autoconf --version | head -n1 | awk '{print $4}')
    AUTOMAKE_VERSION=$(automake --version | head -n1 | awk '{print $4}')
    MAKE_VERSION=$(make --version | head -n1 | awk '{print $3}')
elif [ "$OS" == "ubuntu" ]; then
    BIT=$(getconf LONG_BIT)
    GCC_VERSION=$(gcc --version | head -n1 | awk '{print $3}')
    GCC_CXX_VERSION=$(g++ --version | head -n1 | awk '{print $3}')
    LIBTOOL_VERSION=$(libtool --version | head -n1 | awk '{print $4}')
    AUTOCONF_VERSION=$(autoconf --version | head -n1 | awk '{print $4}')
    AUTOMAKE_VERSION=$(automake --version | head -n1 | awk '{print $4}')
    MAKE_VERSION=$(make --version | head -n1 | awk '{print $3}')
fi

# 결과 출력
echo "운영체제: $OS"
echo "운영체제 비트: $BIT"
echo "GCC Compiler 버전: $GCC_VERSION"
echo "gcc-c++ 버전: $GCC_CXX_VERSION"
echo "libtool 버전: $LIBTOOL_VERSION"
echo "autoconf 버전: $AUTOCONF_VERSION"
echo "automake 버전: $AUTOMAKE_VERSION"
echo "make 버전: $MAKE_VERSION"

스크립트 파일에 실행 권한을 부여

chmod +x check_system.sh

스크립트 실행

./check_system.sh
$ ./check_system.sh
운영체제: ubuntu
운영체제 비트: 64
GCC Compiler 버전: 9.3.0
gcc-c++ 버전: 9.3.0
libtool 버전: 2.4.6
autoconf 버전: 2.69
automake 버전: 1.16.1
make 버전: 4.2.1
728x90

gv.sh 스크립트 생성

vim gv.sh
#!/bin/bash

# 운영체제 버전 출력
echo "운영체제 버전 =>"
if [ -f /etc/redhat-release ]; then
    cat /etc/redhat-release
elif [ -f /etc/os-release ]; then
    os_description=$(cat /etc/os-release | grep "PRETTY_NAME" | cut -d"=" -f2 | cut -d"\"" -f2)
    echo "$os_description"
else
    echo "Other"
fi

# 비트 출력
bit=$(getconf LONG_BIT)
echo "BIT => $bit"

# 커널 버전 출력
kernel_version=$(uname -r)
echo "kernel version => $kernel_version"
echo "--"

# GCC 및 gcc-c++ 버전 출력
echo "GCC Compiler 버전"
gcc_version=$(gcc --version)
gcc_cxx_version=$(g++ --version)
echo "gcc version => $gcc_version"
echo "gcc-c++ version => $gcc_cxx_version"
echo "--"

# libtool 버전 출력
echo "libtool version =>"
if [ -f /etc/redhat-release ]; then
    libtool_version=$(libtool --version)
else
    libtool_version=$(libtoolize --version)
fi
echo "$libtool_version"

# autoconf 및 automake 버전 출력
echo -e "\nautoconf version => $(autoconf --version)"
echo -e "\nautomake version => $(automake --version)"
echo "--"

# make 버전 출력
make_version=$(make --version)
echo "make version => $make_version"

스크립트 파일에 실행 권한을 부여

chmod +x gv.sh

스크립트 실행

./gv.sh
$ ./gv.sh
운영체제 버전 => Ubuntu 20.04.1 LTS
BIT => 64
kernel version => 5.4.0-65-generic
--
GCC Compiler 버전
gcc version =>
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc-c++ version =>
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

--
libtool version =>
libtoolize (GNU libtool) 2.4.6
Written by Gary V. Vaughan <gary@gnu.org>, 2003

Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

autoconf version =>
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.

automake version =>
automake (GNU automake) 1.16.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.
--
make version =>
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

 

728x90
반응형