{"id":404,"date":"2012-02-29T01:13:56","date_gmt":"2012-02-29T01:13:56","guid":{"rendered":"http:\/\/joelinoff.com\/blog\/?p=404"},"modified":"2026-06-28T17:38:42","modified_gmt":"2026-06-29T00:38:42","slug":"bash-script-for-uniquely-identifying-linux-and-solaris-platforms","status":"publish","type":"post","link":"https:\/\/joelinoff.com\/blog\/?p=404","title":{"rendered":"Bash script for uniquely identifying linux and solaris platforms"},"content":{"rendered":"This bash script creates a unique platform identifier string for linux (including cygwin) and solaris. It is useful for creating directory trees on network shared volumes that store data for different OS&#8217;s.\n<!--more-->\n\n<pre class=\"wp-block-code language-bash\"><code class=\"language-bash\">#!\/bin\/bash\n#\n# Determine the current linux or solaris platform and output a unique\n# identifier string. Includes cygwin support.\n#\n# It is useful for creating directory trees on network shared volumes\n# that store data for different OS's.\n#\n# Example:\n#    % export PATH=\/tools\/`~\/bin\/platform.sh`\/bin:\"${PATH}\"\n#\n# The format of the output is:\n#   -&lt;dist&gt;-&lt;ver&gt;-&lt;arch&gt;\n#   ^      ^      ^     ^\n#   |      |      |     +----- architecture: x86_64, i86pc, etc.\n#   |      |      +----------- version: 5.5, 4.7\n#   |      +------------------ distribution: centos, rhel, nexentaos\n#   +------------------------- platform: linux, sunos\n#\n\n# ================================================================\n# Trim a string, remove internal spaces, convert to lower case.\n# ================================================================\nfunction get-platform-trim {\n    local s=$(echo \"$1\" | tr -d '[ \\t]' | tr 'A-Z' 'a-z')\n    echo $s\n}\n\n# ================================================================\n# Get the platform root name.\n# ================================================================\nfunction get-platform-root\n{\n    if which uname &gt;\/dev\/null 2&gt;&amp;1 ; then\n        # Greg Moeller reported that the original code didn't\n        # work because the -o option is not available on solaris.\n        # I modified the script to correctly identify that\n        # case and recover by using the -s option.\n        if uname -o &gt;\/dev\/null 2&gt;&amp;1 ; then\n            # Linux distro\n            uname -o | tr 'A-Z' 'a-z'\n        elif uname -s &gt;\/dev\/null 2&gt;&amp;1 ; then\n            # Solaris variant\n            uname -s | tr 'A-Z' 'a-z'\n        else\n            echo \"unkown\"\n        fi\n    else\n        echo \"unkown\"\n    fi\n}\n\n# ================================================================\n# Get the platform identifier.\n# ================================================================\nfunction get-platform\n{\n    plat=$(get-platform-root)\n    case \"$plat\" in\n        \"gnu\/linux\")\n            d=$(get-platform-trim \"$(lsb_release -i)\" | awk -F: '{print $2;}')\n            r=$(get-platform-trim \"$(lsb_release -r)\" | awk -F: '{print $2;}')\n            m=$(get-platform-trim \"$(uname -m)\")\n            if [[ \"$d\" == \"redhatenterprise\"* ]] ; then\n                # Need a little help for Red Hat because\n                # they don't make the minor version obvious.\n                d=\"rhel_${d:16}\"  # keep the tail (e.g., es or client)\n                x=$(get-platform-trim \"$(lsb_release -c)\" | \\\n                    awk -F: '{print $2;}' | \\\n                    sed -e 's\/[^0-9]\/\/g')\n                r=\"$r.$x\"\n            fi\n            echo \"linux-$d-$r-$m\"\n            ;;\n        \"cygwin\")\n            x=$(get-platform-trim \"$(uname)\")\n            echo \"linux-$x\"\n            ;;\n        \"sunos\")\n            d=$(get-platform-trim \"$(uname -v)\")\n            r=$(get-platform-trim \"$(uname -r)\")\n            m=$(get-platform-trim \"$(uname -m)\")\n            echo \"sunos-$d-$r-$m\"\n            ;;\n        \"unknown\")\n            echo \"unk-unk-unk-unk\"\n            ;;\n        *)\n            echo \"$plat-unk-unk-unk\"\n            ;;\n    esac\n}\n\n# ================================================================\n# main\n# ================================================================\nget-platform<\/code><\/pre>\n\n\n","protected":false},"excerpt":{"rendered":"<p>This bash script creates a unique platform identifier string for linux (including cygwin) and solaris. It is useful for creating directory trees on network shared volumes that store data for different OS&#8217;s.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-404","post","type-post","status-publish","format-standard","hentry","category-bash"],"_links":{"self":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=404"}],"version-history":[{"count":11,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":1799,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/404\/revisions\/1799"}],"wp:attachment":[{"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joelinoff.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}