Abstraction is a technique (Web site counters) used to hide the

Abstraction is a technique used to hide the differences between the versions of UNIX inside shell functions. By doing this, the overall flow of a shell script is not affected. When a function is called, it makes a decision as to what commands to execute. In this section you look at two different examples of abstraction: l Adapting the getFreeSpace function to run on HP-UX l Adapting the getPID function to run on BSD and System V You make use of the functions getOSName and isOS given earlier in this chapter in order to adapt these functions. Adapting getFreeSpace for HP-UX Recall the getFreeSpace function introduced in Chapter 21: getFreeSpace() { if [ $# -lt 1 ] ; then echo “ERROR: Insufficient Arguments.” >&2 return 1 fi DIR=”$1″ if [ ! -d “$DIR” ] ; then DIR= /usr/bin/dirname $DIR fi df -k “$DIR” | awk ‘NR != 1 { print $4 ; }’ } This function prints the amount of free space in a directory in kilobytes. You use this function’s output in the isSpaceAvailable function to determine whether there is enough space in a particular directory. Although this works for most systems (Solaris, Linux, BSD), the output of df -k on HP-UX is much different. For example, $ df -k /usr/sbin /usr (/dev/vg00/lvol8 ) : 737344 total allocated Kb 368296 free allocated Kb 369048 used allocated Kb 50 % allocation used To get a single output line, you need to use the command df -b instead: $ df -b /usr/sbin /usr (/dev/vg00/lvol8 ) : 392808 Kbytes free In order to use isSpaceAvailable on all systems, including HP-UX, you need to change the function
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply