Archive for February, 2008

Sams Teach Yourself Shell Programming in 24 Hours (Disney web site)

Tuesday, February 12th, 2008

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 24: Shell Programming FAQs Previous Chapter Next Chapter Sections in this Chapter: Shell and Command Questions File and Directory Questions Variable and Argument Questions Summary Previous Section Next Section Hour 24 Shell Programming FAQs Each of the previous chapters has focused on an individual topic in shell programming, such as variables, loops, or debugging. As you progressed through the book, you worked on problems that required knowledge from previous chapters. In this chapter, I’m taking a slightly different approach. I will try to answer some common shell programming questions that frequently arise. Specifically I will cover questions from three main areas of shell programming: l The shell and commands l Variables and arguments l Files and directories Each section includes several common questions (along with answers) that occur in shell programming. These questions are designed to help you solve or avoid problems while programming using the shell. Some of the questions provide deeper background information about UNIX, whereas others illustrate concepts covered in previous chapters. Shell and Command Questions In this section I will cover some of the common questions that arise in regard to the shell itself. Also included are a few questions regarding the execution of commands. Why does #!/bin/sh have to be the first line of my scripts? In Chapter 2, “Script Basics,” I stated that #!/bin/sh must be the first line in your script to ensure that the correct shell is used to execute your script. This line must be the first line in your shell script because of the underlying mechanism used by a shell to execute commands. When you ask a shell to execute the command $ date, the shell uses the system call exec to ask the UNIX kernel to execute the command you requested. For those readers who are not familiar with the term system call, a system call is a C language function built in to the UNIX kernel that enables you to access features of the kernel. The shell passes the name of the command that should be executed to the exec system call. This system call reads the first two characters in a file to determine how to execute the command. In the case of shell scripts, the first two characters are #!, indicating that the script needs to be interpreted by another program
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Sams Teach Yourself Shell Programming in 24 Hours (Web site layout)

Monday, February 11th, 2008

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Terms Conditional Execution Conditional execution alters the execution of a script based on the system type. A script that uses conditional execution usually contains an if statement at the beginning that sets variables to indicate the commands to use on a particular platform. Abstraction Scripts that use abstraction retain the same basic flow by placing the conditional execution statements within functions. When a function is called, it makes a decision as to what commands execute for a given platform. Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Sams Teach Yourself Shell Programming (Sri lanka web server) in 24 Hours

Saturday, February 9th, 2008

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Questions 1. Write a function called getCharCount that prints the number of characters in a file. Use wc to obtain the character count. On Linux, FreeBSD, and SunOS (not Solaris), use the -c option for wc,. On other versions of UNIX, use the -m option instead. You can use the function getOSName to get the name of the operating system. Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Sams Teach Yourself Shell Programming in 24 Hours (Web site directory)

Friday, February 8th, 2008

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Summary In this chapter, you learned how to determine which version of UNIX you are running by using the uname command. In addition, you developed the getOSName and isOS functions to help you adapt your shell scripts to multiple versions of UNIX. You also looked at the following techniques for improving the portability of shell scripts: l Conditional execution l Abstraction In conditional execution, you modify the flow of your script depending on the version of UNIX being used. In abstraction, you change the implementation of your functions to account for the differences between the versions of UNIX. Here, the flow of your script remains the same. Using the techniques and tips in this chapter, you can port your shell script across different versions of UNIX. Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Web hosting support - warning: ‘-’ deprecated; use ‘ps auwx’, not ‘ps

Thursday, February 7th, 2008

warning: ‘-’ deprecated; use ‘ps auwx’, not ‘ps -auwx’ By using the getOSName function given earlier in this chapter, we can adapt the getPID function to work with both the BSD and System V versions of ps. The modified version of getPID is as follows: getPID() { if [ $# -lt 1 ] ; then echo “ERROR: Insufficient Arguments.” >&2 return 1 fi case getOSName in bsd|sunos|linux) PSOPTS=”-auwx” ;; *) PSOPTS=”-ef” ;; esac /bin/ps $PSOPTS 2> /dev/null | grep “$1″ | grep -v grep | awk ‘{ print $2; }’ } The two main changes are l A case statement sets the variable PSOPTS based on the operating system name. l The STDERR of ps is redirected to /dev/null in order to discard the warning message generated on newer versions of Linux. Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Web server version - getFreeSpace to take these factors into account. The

Wednesday, February 6th, 2008

getFreeSpace to take these factors into account. The modified version looks like the following: 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 if isOS HPUX ; then df -b “$DIR” | awk ‘{ print $5 ; }’ else df -k “$DIR” | awk ‘NR != 1 { print $4 ; }’ fi } Here, you are calling the isOS function given earlier in this chapter to determine which commands to execute. Adapting getPID for BSD UNIX Recall the getPID function introduced in Chapter 21: getPID() { if [ $# -lt 1 ] ; then echo “ERROR: Insufficient Arguments.” >&2 return 1 fi PSOPTS=”-ef” /bin/ps $PSOPTS | grep “$1″ | grep -v grep | awk ‘{ print $2; }’ } Remember that it works correctly only on systems where the command ps -ef produces a listing of all running processes. This is not the case on Linux and BSD systems. On BSD systems, we need to use the command ps -auwx to get the correct output. This works on older Linux systems, but on newer Linux systems an error message similar to the following is generated:
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

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

Tuesday, February 5th, 2008

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.

A script (Web server address) that needs to execute commands on

Monday, February 4th, 2008

A script that needs to execute commands on a remote system might have an if statement of the following form at its beginning: if SystemIS HPUX ; then RCMD=remsh else RCMD=rsh fi After the variable $RCMD is set, remote commands can execute as follows: “$RCMD” host command Here, host is the hostname of the remote system, and command is the command to execute. Problems with the echo Command in Prompts Most programs that need to prompt the user need to be able to print a prompt that is not terminated by a newline. In Chapter 13, “Input/Output,” there were several problems with using the c escape sequence of the echo command to do this. The workaround was to use the /bin/echo command. Although this works for UNIX versions based on System V, on some BSD-based systems this does not work. You need to specify the -n option to echo instead. By using the following shell script, you can create a shell function, echo_prompt, to display a prompt reliably across all versions of echo: _ECHO=/bin/echo _N= _C=”c” ECHOOUT= $_ECHO “hello $_C” if [ “$ECHOOUT” = “hello c” ] ; then _N=”-n” _C= fi export _ECHO _N _C echo_prompt() { $_ECHO $_N $@ $_C ; } This script fragment implements the /bin/echo workaround by using it as the base from which to construct the correct echo command. It then checks the output of an echo command to see whether the c sequence is treated correctly. If it is not, you need to use the -n option. After this has been determined, the function echo_prompt is created using the correct variables. This function enables us to reliably output prompts, as in the following example: $ echo_prompt “Do you want to play a game?” ; read response Do you want to play a game? Abstraction
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Sams Teach Yourself Shell Programming (Yahoo web space) in 24 Hours

Sunday, February 3rd, 2008

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Techniques for Increasing Portability Conditional Execution Abstraction Shell scripts that run on multiple versions of UNIX often include code that is version-specific. For example, you might need to use a different command on Linux than Solaris to obtain some system information. There are two common techniques to increase the portability of a shell script between different versions of UNIX: l Conditional execution l Abstraction Conditional execution alters the execution of a script based on the system type, whereas abstraction retains the same basic flow of the script by placing the conditional statements within functions. Conditional Execution A script that uses conditional execution for portability contains an if statement at the beginning. The if statement sets several variables indicating the set of commands to use on a particular platform. In this section, you look at two common cases of conditional execution: l Determining the remote shell command l Determining the proper method of using the echo command in prompts The first case illustrates setting a variable based on the operating system type. The second case illustrates setting variables based on the behavior of a command ( echo) on a particular system. Executing Remote Commands A common use of conditional execution is in scripts that need to execute commands on remote systems. On most versions of UNIX, you can use the rsh (remote shell) command to execute commands on a remote system. Unfortunately, you cannot use this command on all versions of UNIX. On HP-UX, rsh is available, but it is not the remote shell program–it is the restricted shell program. On HPUX, you need to use the command remsh to execute commands on a remote system.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

: # HP-UX (Web host server) specific commands here elif isOS

Saturday, February 2nd, 2008

: # HP-UX specific commands here elif isOS solaris ; then : # Solaris specific comands here else : # generic unix commands here fi The reason that you do not directly check the value of $1 but instead use the variable REQ, is that this enables a greater flexibility on the part of the function’s user. For example, you can use either of the following to check whether a system is Linux: isOS LINUX isOS linux Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 23: Scripting for Portability Previous Chapter Next Chapter Sections in this Chapter: Determining UNIX Versions Questions Techniques for Increasing Portability Terms Summary Previous Section Next Section Copyright Macmillan Computer Publishing. All rights reserved.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.