Now that you have looked at using the (Crystaltech web hosting)
Friday, February 1st, 2008Now that you have looked at using the uname command to gather information about the version of UNIX that is being used, you need a method for using this information in a shell script. As you saw in Chapter 21, “Problem Solving With Functions,” creating a shell function that determines the version of UNIX gives the greatest flexibility. A shell function that returns the operating system type is as follows: getOSName() { case uname -s in *BSD) echo bsd ;; SunOS) case uname -r in 5.*) echo solaris ;; *) echo sunos ;; esac ;; Linux) echo linux ;; HP-UX) echo hpux ;; AIX) echo aix ;; *) echo unknown ;; esac } As you can see, this function is not very complicated. It checks the output of uname -s and looks for a match. In the case of SunOS, it also checks the output of uname -r to determine whether the operating system is Solaris or SunOS. In many cases, you need to tailor the options of a command, such as ps or df, so that the command can generate the desired output. In such cases, you need the capability to “ask” whether the operating system is of a certain type. A shell function that performs this task follows: isOS() { if [ $# -lt 1 ] ; then echo “ERROR: Insufficient Aruments.” >&2 return 1 fi REQ= echo $1 | tr ‘[A-Z]’ ‘[a-z]’ if [ “$REQ” = ” getOSName ” ] ; then return 0 ; fi return 1 } This function compares its first argument to the output of the function getOSName and returns 0 (true) if they are the same; otherwise, it returns 1 (false). Using this function, you write if statements of the following type: if isOS hpux ; then
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.