Archive for December, 2007

Web site builder - 9 printERROR() { 10 echo “ERROR:” $@ >&2

Sunday, December 30th, 2007

9 printERROR() { 10 echo “ERROR:” $@ >&2 11 } 12 13 ################################################ 14 # Name: printWARNING 15 # Desc: prints an message to STDERR 16 # Args: $@ -> message to print 17 ################################################ 18 19 printWARNING() { 20 echo “WARNING:” $@ >&2 21 } 22 23 ################################################ 24 # Name: printUSAGE 25 # Desc: prints a USAGE message and then exits 26 # Args: $@ -> message to print 27 ################################################ 28 29 printUSAGE() { 30 echo “USAGE:” $@ 31 exit 32 } 33 34 ################################################ 35 # Name: promptYESNO 36 # Desc: ask a yes/no question 37 # Args: $1 -> The prompt 38 # $2 -> The default answer (optional) 39 # Vars: YESNO -> set to the users response 40 # y for yes, n for no 41 ################################################ 42 43 promptYESNO() { 44 45 if [ $# -lt 1 ] ; then 46 printERROR “Insufficient Arguments.” 47 return 1 48 fi 49 50 DEF_ARG=”" 51 YESNO=”" 52 53 case “$2″ in 54 [yY]|[yY][eE][sS]) 55 DEF_ARG=y ;; 56 [nN]|[nN][oO]) 57 DEF_ARG=n ;; 58 esac 59 60 while : 61 do 62
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Web hosting isp - getUID() { id $1 | sed -e ’s/(.*$//’

Sunday, December 30th, 2007

getUID() { id $1 | sed -e ’s/(.*$//’ -e ’s/^uid=//’ } This function executes the id command and then uses a sed filter to delete all the unimportant information. When the function is called by itself getUID the output looks like the following: 500 When the function is called with a username getUID vathsa the output looks like the following: 500 Usually you need to compare this output to some known UID as follows: if [ ” getUID ” -gt 100 ] ; then printERROR “You do not have sufficient privileges.” exit 1 fi Here the output of the getUID function is checked to see whether it is greater than 100. The Complete Library Listing 21.1 contains a complete listing of the shell library, libTYSP.sh, discussed in this chapter. The line numbers are present for your reference and should not be entered into a script library file that you plan to use. Listing 21.1–Complete Listing of the Shell Library libTYSP.sh 1 #!/bin/sh 2 3 ################################################ 4 # Name: printERROR 5 # Desc: prints an message to STDERR 6 # Args: $@ -> message to print 7 ################################################ 8
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Web design careers - Because the process ID is stored in the

Saturday, December 29th, 2007

Because the process ID is stored in the second column, use awk to extract it. If more than one line matches, this function displays each process ID. For example, the following command getPID httpd returns the following list of process IDs on my system: 330 331 332 333 334 335 336 323 Readers who are using Linux or FreeBSD-based systems have to change this function slightly for it to function properly. The value of the variable PSOPTS should be -auwx on these systems. In Chapter 23, I will show you how to incorporate these changes into the function so that it runs on all versions of UNIX. Getting a User’s Numeric User ID Some shell scripts need to determine whether a user has sufficient permissions to execute commands. For example, an install script might need to run as root (UID 0) to modify system files correctly. In other instances, a script might need to detect whether a user has too many privileges. To check the user’s ID, you can use the id command, which can be run in two forms. The first form specifies a username whose ID should be returned. For example, the command $ id vathsa uid=501(vathsa) gid=100(users) groups=100(users) returns the UID for the user vathsa. The second form omits the user ID. In this form, the current user’s information is returned. $ id uid=500(ranga) gid=100(users) groups=100(users),101(ftpadmin) Your function supports both. ################################################ # Name: getUID # Desc: outputs a numeric user id # Args: $1 -> a user name (optional) ################################################
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Web hosting service - The number returned is in kilobytes, which means

Friday, December 28th, 2007

The number returned is in kilobytes, which means that the directory /usr/local uses about 15.1MB. Frequently, you’ll want to compare the output of this function to some value. For example, the following if statement checks to see whether more than 10,000KB are used by the directory /home/ranga/pub: if [ ” getSpaceSpace /home/ranga/pub ” -gt 10000 ] ; then printWARNING “You’re using to much space!” fi Obtaining the Process ID by Name One of the difficulties with the ps command is that it is hard to obtain the process ID of a command by specifying only its name. In shell scripts that have to start and stop processes, the capability to look through the output of ps and retrieve a list of process IDs based on a command’s name is essential. In this section, I will present a function that displays a list of process IDs (pids) based on a string supplied by the user. ################################################ # Name: getPID # Desc: outputs a list of process id matching $1 # Args: $1 -> the command name to look for ################################################ getPID() { if [ $# -lt 1 ] ; then printERROR “Insufficient Arguments.” return 1 fi PSOPTS=”-ef” /bin/ps $PSOPTS | grep “$1″ | grep -v grep | awk ‘{ print $2; }’ } As you can see, this function is a set of filters on top of the command /bin/ps -ef. The first grep command looks for all lines that match the first argument. As an example, executing this on the command line produces output similar to the following: $ /bin/ps -ef | grep sshd Here you are looking for all the lines that contain the word sshd. The output should look similar to the following: root 1449 1 8 12:23:06 ? 0:02 /opt/bin/sshd ranga 1451 944 5 12:23:08 pts/t0 0:00 grep sshd As you can see, the output contains two lines. The first one contains the process ID of the commands that you are looking for, but the second contains the process ID of the grep command that just executed. In order to get rid of such lines, add the grep -v grep to the pipeline.
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

You have looked at determining the amount (Best web hosting) of

Thursday, December 27th, 2007

You have looked at determining the amount of disk space available in a directory, but sometimes you need to know how much disk space a directory uses. For example, you might have a public directory that needs to be cleaned out when it exceeds a certain size. To perform this task, you need to use the du ( du as in disk usage) command. Because you want the output for an entire directory and its contents, you need to specify the -s ( s as in sum) option to du. You also need to specify the -k ( k as in kilobyte) option for a consistent output on all versions of UNIX. The output of the du -sk command looks like the following: $ du -sk /home/ranga/pub 4922 /home/ranga/pub The size of the directory in kilobytes is listed in the first column. Your function uses awk to obtain this number. ################################################ # Name: getSpaceUsed # Desc: output the space used for a directory # Args: $1 -> The directory to check ################################################ getSpaceUsed() { if [ $# -lt 1 ] ; then printERROR “Insufficient Arguments.” return 1 fi if [ ! -d “$1″ ] ; then printERROR “$1 is not a directory.” return 1 fi du -sk “$1″ | awk ‘{ print $1 ; }’ } This function is almost as simple as getSpaceFree. It first checks whether it was given an argument. If no argument was given, it displays an error message and returns. Otherwise, it checks to see whether the first argument is a directory. If it is not, an error message is displayed and the function returns. Otherwise, the function executes the du -sk command and displays the number stored in the first column. As an example of using this function, the command getSpaceUsed /usr/local displays the following value on my system: 15164
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Web hosting servers - /dev/hda1 1190014 664661 463867 59% / The output

Wednesday, December 26th, 2007

/dev/hda1 1190014 664661 463867 59% / The output consists of a header line and information about the hard drive or hard drive partition that the directory or file you specified is located on. In this output, the amount of free space is stored in the fourth column. Your function uses awk to get at this value. ################################################ # Name: getSpaceFree # Desc: output the space avail for a directory # Args: $1 -> The directory to check ################################################ getSpaceFree() { if [ $# -lt 1 ] ; then printERROR “Insufficient Arguments.” return 1 fi df -k “$1″ | awk ‘NR != 1 { print $4 ; }’ } As you can see, the function is quite simple. It first checks to see whether it was given an argument. If no argument was given, it displays an error message and returns. Otherwise, it runs the df -k command and displays the number stored in the fourth column. You use the awk expression NR != 1 to skip the first line that contains the header. For more information on awk, please look at Chapter 17, “Filtering Text with awk.” As an example of using this function, the command getSpaceFree /usr/local displays the following value on my system: 2335788 The number returned is in kilobytes, which means I have about 2.3GB free in the directory /usr/local. Frequently you might want to compare the output of this function to some value. For example, the following if statement checks to see whether more than 20,000KB are available in the directory /usr/local: if [ ” getSpaceFree /usr/local ” -gt 20000 ] ; then echo “Enough space” fi Determining Space Used
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Web file server - In which directory do you want to install

Tuesday, December 25th, 2007

In which directory do you want to install ? If you enter the name of a valid directory, no further prompts are generated; otherwise, you are asked whether the directory should be created: The directory mydir does not exist. Create it (y/n)? [y] Here the default is to create the directory. You can modify the example slightly to provide a default directory as follows: promptRESPONSE “In which directory do you want to install” “$HOME” The prompt changes to look like the following: In which directory do you want to install ? [/home/ranga] Checking Disk Space Shell scripts are commonly used to keep system administrators up to date about the amount of free space available in certain directories. For example, you don’t want the incoming mail directory to fill up. An auxiliary task is to determine how much space a directory uses. For example, you don’t want a single user to hog up all the disk space for extended periods. The information about disk usage is also important to installation scripts because they need to warn a user when an installation is attempted in a directory that does not contain enough space. In this section, I will present two functions that can help you determine disk space usage: l getSpaceFree l getSpaceUsed Determining Free Space To determine the free space in a directory, you use the df -k ( k as in KB) command. Its output looks like the following: $ df -k Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hda1 1190014 664661 463867 59% / /dev/hdd1 4128240 1578837 2335788 40% /internal /dev/hdb1 1521567 682186 760759 47% /store /dev/hda3 320086 72521 231034 24% /tmp When run on a single directory or file, the output looks like the following: $ df -k /home/ranga Filesystem 1024-blocks Used Available Capacity Mounted on
We recommend high quality webhost to host and run your jsp application: christian web host services.

Web space - } Before you look at some examples of

Monday, December 24th, 2007

} Before you look at some examples of this function in use, examine how it works. This function is quite similar to the promptYESNO function. As indicated by the comments, promptRESPONSE can handle up to two arguments. It treats the first argument as the prompt and the second argument as the default answer to the prompt. The first thing this function checks for is that at least one argument is given. If no arguments are given, you return from the function with the following error message: ERROR: Insufficient Arguments. Next you set the variable RESPONSE to null to avoid using a value stored in it from a previous call to this function. After this, you set DEF_ARG, the default answer, to the value of the second argument of the function, $2. If the second argument is not given, DEF_ARG is set to null, because of variable substitution. At this point, you enter the body of an infinite while loop. You call the break command from inside the while loop after the user has entered a valid answer. The first thing the loop does is display a prompt using the printf command. You use the printf command to avoid problems with the echo command between different versions of UNIX. If a valid default answer was specified, you display it out. After the prompt is displayed, you call the read command and read the user’s response into the variable RESPONSE. If the user entered a value, you call the break command to exit the while loop. If the user simply presses Enter, RESPONSE is set to null. In this case, you check to see whether DEF_ARG contains a default answer. If it does, you set RESPONSE to this value and call the break command to exit the while loop. This behavior is similar to the promptYESNO function. If the default argument was not given and the user presses Enter, the prompt is displayed again. After a valid response is given, the while loop terminates. When this happens, the function exports the variable RESPONSE to the environment and returns by calling the return command. Now that you know how this function works, look at an example of its use. The following set of commands could be used in an install script: promptRESPONSE “In which directory do you want to install” if [ ! -d “$RESPONSE” ] ; then echo “The directory $RESPONSE does not exist.” promptYESNO “Create it” “y” if [ “$YESNO” = “y” ] ; then mkdir “$RESPONSE” else exit fi fi At first you are prompted as follows:
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Make Backup (y/n)? [y] This (Web server application) lets the user

Sunday, December 23rd, 2007

Make Backup (y/n)? [y] This lets the user simply press Enter and have the backup made. It also lets the user type a response. Prompting for a Response In many shell scripts, you need to gather more information from the user than a yes or no response. For example, installation scripts frequently have to ask for the name of a directory, the location of a file, or other system information. The promptYESNO function cannot handle these types of questions. You need a different kind of prompting function, which you present as the promptRESPONSE function. This function displays a prompt, reads the user’s response, and stores it in the variable RESPONSE. Validation of the user’s response needs to be handled outside of the function. ################################################ # Name: promptRESPONSE # Desc: ask a question # Args: $1 -> The prompt # $2 -> The default answer (optional) # Vars: RESPONSE -> set to the users response ################################################ promptRESPONSE() { if [ $# -lt 1 ] ; then printERROR “Insufficient Arguments.” return 1 fi RESPONSE=”" DEF_ARG=”$2″ while : do printf “$1 ? ” if [ -n “$DEF_ARG” ] ; then printf “[$DEF_ARG] ” fi read RESPONSE if [ -n “$RESPONSE” ] ; then break elif [ -z “$RESPONSE” -a -n “$DEF_ARG” ] ; then RESPONSE=”$DEF_ARG” break fi done export RESPONSE unset DEF_ARG return 0
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

previous call to this function. (Web host 4 life) After this, try

Saturday, December 22nd, 2007

previous call to this function. After this, try to set DEF_ARG, the default answer, by looking at the value of the second argument to the function, $2. If this argument is some form (regardless of case) of the words YES or NO, you set DEF_ARG; otherwise, you leave it as null. At this point, you enter the body of an infinite while loop. You call the break command from inside the while loop after the user has entered a valid answer (some form of the words YES or NO). The first thing the loop does is output a prompt using the printf command. You use the printf command to avoid problems with the echo command between different versions of UNIX. If a valid default answer was specified, you display it. After the prompt is displayed, call the read command and read the user’s response into the variable YESNO. If the user simply presses Enter, YESNO is set to null. In this case, you set it equal to the default answer stored in DEF_ARG. If the default argument was not given, this assignment is redundant. The last step in the while loop is to check the value of YESNO and make sure that it contains some form of the words YES or NO. If it does, you call the break command to terminate the while loop. If YESNO contains an invalid response, the loop repeats. This means that if the user simply types Enter in a case where no default was supplied, or if the user enters a response that the function does not understand, the same prompt is displayed again. Before the function exits, it exports the variable YESNO to the environment to make sure that this variable is available to commands executed after the function exits. Now that you know how this function works, look at an example of its use, as illustrated here: promptYESNO “Make backup” if [ “$YESNO” = “y” ] ; then cp -r docs backup fi This generates a prompt similar to the following: Make Backup (y/n)? If you enter some form of the words YES or NO, the function sets the variable YESNO to either y or n. The if statement in this example evaluates this response and performs the appropriate action. Here you execute a cp command. If the user does not enter a valid response, the prompt repeats. You can use a default argument as follows: promptYESNO “Make backup” “y” if [ “$YESNO” = “y” ] ; then cp -r docs backup fi Now the prompt looks like the following:
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.