Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@josephbolus
Created October 8, 2013 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephbolus/6881075 to your computer and use it in GitHub Desktop.
Save josephbolus/6881075 to your computer and use it in GitHub Desktop.
#!bin/bash
############################################################
# Print OS summary (OS, ARCH, VERSION)
############################################################
function print_info {
echo -n -e '\e[1;36m'
echo -n $1
echo -e '\e[0m'
}
function show_os_arch_version {
# Thanks for Mikel (http://unix.stackexchange.com/users/3169/mikel) for the code sample which was later modified a bit
# http://unix.stackexchange.com/questions/6345/how-can-i-get-distribution-name-and-version-number-in-a-simple-shell-script
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
VERSION=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Work on Debian and Ubuntu alike
OS=$(lsb_release -si)
VERSION=$(lsb_release -sr)
elif [ -f /etc/redhat-release ]; then
# Add code for Red Hat and CentOS here
OS=Redhat
VERSION=$(uname -r)
else
# Pretty old OS? fallback to compatibility mode
OS=$(uname -s)
VERSION=$(uname -r)
fi
OS_SUMMARY=$OS
OS_SUMMARY+=" "
OS_SUMMARY+=$VERSION
OS_SUMMARY+=" "
OS_SUMMARY+=$ARCH
OS_SUMMARY+="bit"
print_info "$OS_SUMMARY"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment