<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Welcome to the World of Linux</title>
	<link>http://www.linux-bloggersplace.org</link>
	<description>Linux Blog &#124; Learn Linux Tricks</description>
	<pubDate>Thu, 12 Jun 2008 11:42:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>
	<language>en</language>
			<item>
		<title>The for Loop</title>
		<link>http://www.linux-bloggersplace.org/2007/12/07/the-for-loop/</link>
		<comments>http://www.linux-bloggersplace.org/2007/12/07/the-for-loop/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 09:14:10 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[commands]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/12/07/the-for-loop/</guid>
		<description><![CDATA[The for loop is used to process a list of items. The list can be supplied in the script. It could also be taken from the script arguments, from a file, or from the output of a command. 
The syntax of the for construct is as follows:
for list
do
command_list
done
All the commands in the list are carried [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">The for loop is used to process a list of items. The list can be supplied in the script. It could also be taken from the script arguments, from a file, or from the output of a command. </p>
<p>The syntax of the for construct is as follows:</p>
<p>for list<br />
do<br />
command_list<br />
done</p>
<p>All the commands in the list are carried out for each item in the list.</p>
<p align="justify">The following script invokes the C compiler cc for all files with the extension of .c held in the current directory.</p>
<p><code><br />
for filename in $(ls *.4gl)<br />
do<br />
cc $filename<br />
done<br />
</code></p>
<p align="justify">A similar script could be written to compile several programs specified on the command line. The user can specify as many programs as he wants.</p>
<p><code><br />
for filename in $*<br />
do<br />
cc $filename<br />
done<br />
</code></p>
<p>$* expands to all the arguments given by the user. Each argument will count as a single item in the list.</p>
<p align="justify">This construct is very useful for working with commands that give more than one line of output. Note, however, that the loop will be carried out for each word of the output, rather than once for each line. Commands whose output consist of several columns separated by spaces will be treated as one list item for each column of each row.</p>
<p align="justify">To illustrate this, we will look at a script that takes the output from the ps command, and attempts to process it as a list. The output from ps looks something like this:</p>
<p>   PID TTY         TIME CMD<br />
  3218 pts/2       0:01 ksh<br />
  3207 pts/2       0:00 sh<br />
  3550 pts/2       0:00 ps</p>
<p>The script is as follows:</p>
<p><code><br />
for process in $(ps)<br />
do<br />
echo $process<br />
done<br />
</code></p>
<p>and gives the following output:</p>
<p>PID<br />
TTY<br />
TIME<br />
CMD<br />
3218<br />
pts/2<br />
0:01<br />
ksh<br />
3207<br />
pts/2<br />
0:00<br />
sh<br />
3579<br />
pts/2<br />
0:00<br />
ps<br />
3578<br />
pts/2<br />
0:00<br />
ksh</p>
<p align="justify">If we wanted to carry out commands on each line rather than on each word, and ignore the column headings, we would have to use some ingenuity. The following script displays the PID and command from each line output from the ps command.</p>
<p><font style="position: absolute;overflow: hidden;height: 0;width: 0"><a href="http://kvantservice.com/">компютри</a></font></p>
<p><code><br />
count1=0<br />
count2=0<br />
for process in $(ps)<br />
do<br />
count1=$(($count1 + 1))<br />
if test $count1 -lt 5<br />
   then<br />
   continue<br />
fi<br />
count2=$(($count2 + 1))</p>
<p>if test $count2 -eq 1<br />
   then<br />
   pid=$process<br />
fi<br />
if test $count2 -eq 4<br />
   then<br />
   cmd=$process<br />
   echo $pid $cmd<br />
   count2=0<br />
fi<br />
done<br />
</code></p>
<p>The output would look like this:</p>
<p>3218 ksh<br />
3207 sh<br />
3609 ps<br />
3608 ksh</p>
<p align="justify">The script uses two counters. The first, count1, is used to skip out the headings. The first four items in the list are headings, so if the counter is less than 5, it uses the continue command to skip all further commands for that item. The second counter is used to establish which column of the ps output is being processed. When it is column 1, it stores the PID in a variable. For column 4, it stores the command in a variable, echoes both variables to the user, and resets the count to zero.</p>
<p> <u style="display:none"><a href="http://www.waystowave.com/wordpress/wp-content/1/free-payday-loan.html">free payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/low-cost-payday-loan.html">low cost payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/cash-advance-payday-loan.html">cash advance payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/approval-guaranteed-loan-payday.html">approval guaranteed loan payday</a><a href="http://www.waystowave.com/wordpress/wp-content/1/payday-loan-application.html">payday loan application</a><a href="http://www.waystowave.com/wordpress/wp-content/1/yahoo-payday-loan.html">yahoo payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/money-tree-payday-loan.html">money tree payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/loan-money-payday-tree.html">loan money payday tree</a><a href="http://www.waystowave.com/wordpress/wp-content/1/loan-payday-toronto.html">payday loan toronto,payday loan in toronto,loan payday toronto</a><a href="http://www.waystowave.com/wordpress/wp-content/1/loan-payday-yahoo.html">loan payday yahoo</a><a href="http://www.waystowave.com/wordpress/wp-content/1/instant-approval-payday-loan.html">instant approval payday loan,approval instant loan payday</a><a href="http://www.waystowave.com/wordpress/wp-content/1/payday-loan-paycheck-advance.html">payday loan paycheck advance</a><a href="http://www.waystowave.com/wordpress/wp-content/1/credit-loan-no-payday.html">credit loan no payday,credit dollar loan no payday ten,no credit payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/one-hour-payday-loan.html">one hour payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/no-credit-check-payday-loan.html">no credit check payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/calgary-loan-payday.html">calgary loan payday,calgary payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/fast-online-payday-loan.html">fast online payday loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/fast-loan-online-payday.html">fast loan online payday</a><a href="http://www.waystowave.com/wordpress/wp-content/1/advance-loan-payday-quick.html">advance loan payday quick</a><a href="http://www.waystowave.com/wordpress/wp-content/1/quick-payday-advance-loan.html">quick payday advance loan</a><a href="http://www.waystowave.com/wordpress/wp-content/1/military-payday-loan.html">military payday loan</a><a href="http://www.asheghoone.com/wp-content/1/no-fax-cash-advance.html">no fax cash advance,advance cash fax no,account advance cash fax no saving</a><a href="http://www.asheghoone.com/wp-content/1/cash-advance-company.html">advance cash company scams,cash advance company,advance advance cash company heir</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-loan-payday.html">payday payday loan cash advance loan,advance cash loan payday today,advance cash loan payday</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-loan-online.html">advance cash loan online</a><a href="http://www.asheghoone.com/wp-content/1/ace-cash-advance.html">ace cash advance</a><a href="http://www.asheghoone.com/wp-content/1/cash-fast-loan-payday.html">cash fast loan payday</a><a href="http://www.asheghoone.com/wp-content/1/fast-cash-advance.html">fast faxless cash advance,fast cash advance,advance cash fast faxing no</a><a href="http://www.asheghoone.com/wp-content/1/national-cash-advance.html">national cash advance</a><a href="http://www.asheghoone.com/wp-content/1/fast-cash-payday-loan.html">payday us fast cash loan,fast cash payday loan</a><a href="http://www.asheghoone.com/wp-content/1/cash-advance-america.html">advance america cash company,advance america cash loan,cash advance america</a><a href="http://www.asheghoone.com/wp-content/1/cash-loan-payday-until.html">cash loan payday until</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-loan-loan-payday.html">advance cash loan loan payday</a><a href="http://www.asheghoone.com/wp-content/1/advance-america-cash.html">advance america cash</a><a href="http://www.asheghoone.com/wp-content/1/cash-advance-payday-loan-software.html">cash advance payday loan software</a><a href="http://www.asheghoone.com/wp-content/1/business-cash-advance.html">business cash advance loan,business cash advance,how to start a cash advance business</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-loan-payday-software.html">advance cash loan payday software</a><a href="http://www.asheghoone.com/wp-content/1/check-cash-advance.html">advance cash cashing check greenville,greenville,advance cash cashing check durham,durham,check cash advance</a><a href="http://www.asheghoone.com/wp-content/1/first-american-cash-advance.html">first american cash advance</a><a href="http://www.asheghoone.com/wp-content/1/cash-until-payday-loan.html">cash until payday loan</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-overnight.html">advance cash overnight</a><a href="http://www.asheghoone.com/wp-content/1/cash-advance-service.html">cash advance service</a><a href="http://www.asheghoone.com/wp-content/1/cash-loan-payday-til.html">cash loan payday til</a><a href="http://www.asheghoone.com/wp-content/1/first-cash-advance.html">first time cash advance,first choice cash advance,first cash advance</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-company.html">scams on cash advance company,advance cash company</a><a href="http://www.asheghoone.com/wp-content/1/quick-cash-advance.html">advance cash now quick,quick cash advance,quick no fax cash advance</a><a href="http://www.asheghoone.com/wp-content/1/cash-in-advance.html">cash in advance</a><a href="http://www.asheghoone.com/wp-content/1/cash-advance-loan-illinois.html">cash advance loan illinois,5 advance cash illinois loan</a><a href="http://www.asheghoone.com/wp-content/1/advance-cash-check-credit-no.html">advance cash check credit no</a><a href="http://www.asheghoone.com/wp-content/1/advance-america-cash-advance.html">ace advance america cash,advance america cash first,advance america cash advance</a></u> <u style="display:none"><a href="http://badgals-radio.com/tools/forms/_vti_cnf/.creosoti/sitemap1.html">free ringtones maker</a> | <a href="http://www.bitbuster.org/wp-content/plugins/mister-wong-bookmark-this/.redubbed/sitemap1.html">nextel ringtones cd</a> | <a href="http://fromthedeskofmikestewart.com/blog/wp-content/themes/brownbound/brownbound/_vti_cnf/.gradatio/?page=sitemap1">free cingular mp3 ringtones</a> | <a href="http://kathrynseckold.com/components/com_expose/expose/manager/amfphp/services/com/slooz/.rechange/index.php?name=sitemap1">free real ringtones sprint</a> | <a href="http://siodmak.com/wp-content/plugins/.morphemes/sitemap1.html">cell free phone ringtones verizon wireless</a> | <a href="http://www.athlonelite.com/wp-content/themes/glossyblue-1-4/.putons/sitemap1.html">free crazy frog ringtones download</a> | <a href="http://tobias.bindslet.dk/pmwiki/pub/skins/Flash/.nonst/?str=sitemap1">free hindi ringtones</a> | <a href="http://www.pushing-pixels.org/wp-content/themes/grid_focus_public2/.artis/?id=sitemap1">download polyphonic ringtones</a> | <a href="http://navira.com/trista/blog/wp-content/plugins/wp-syntax/geshi/.facilitati/index.php?name=sitemap1">free t mobile ringtones</a> | <a href="http://terrierlover.com/wp-includes/js/tinymce/.subcu/sitemap1.html">verizon lg ringtones</a> | <a href="http://agentask.com/nyc/blog/.allergin/index.php?name=sitemap1">free mp3 ringtones for t mobile</a> | <a href="http://www.rodkar.com/.blunder/?str=sitemap1">free cellular phone ringtones</a> | <a href="http://www.wacdesigns.com/wp-content/themes/J2bata/options/display/.split/?file=sitemap1">download midi ringtones</a> | <a href="http://www.wineyatra.com/include/lang/ja/.feigners/index.php?page=sitemap1">mp3 ringtones creator</a> | <a href="http://www.bdgamers.net/bdpollution/wp-content/themes/classic/.spermiogen/index.php?page=sitemap1">us cellular ringtones</a> | <a href="http://www.fra.interfilmbag.com/administrator/includes/pcl/.crino/sitemap1.html">info personal polyphonic remember ringtones</a> | <a href="http://howtocopewithdepression.com/blog/wp-content/themes/bittersweet/plugin/.theatrical/index.php?name=sitemap1">free phone ringtones</a> | <a href="http://www.accordingtowayne.com/wp-gallery/.maund/index.php?id=sitemap1">absolutely free ringtones</a> | <a href="http://www.xbox-ambassadors.com/wp-content/plugins/.gapped/?str=sitemap1">make your own mp3 ringtones</a> | <a href="http://perifair.de/ordner1/wp-content/themes/lush2/_css/.pang/?id=sitemap1">blue tooth free ringtones</a> | </u></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/12/07/the-for-loop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The While Loop</title>
		<link>http://www.linux-bloggersplace.org/2007/12/07/the-while-loop/</link>
		<comments>http://www.linux-bloggersplace.org/2007/12/07/the-while-loop/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 09:13:08 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[commands]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/12/07/the-while-loop/</guid>
		<description><![CDATA[In common with most programming languages, Unix shell scripting caters for instructions to be carried out repetitively. 
The while loop will repeat a list of commands as long as a given condition is true. All of the conditional statements used in the if&#8230;fi construct can be used here, including string and numeric comparisons, file checking, [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">In common with most programming languages, Unix shell scripting caters for instructions to be carried out repetitively. </p>
<p align="justify">The while loop will repeat a list of commands as long as a given condition is true. All of the conditional statements used in the if&#8230;fi construct can be used here, including string and numeric comparisons, file checking, null checking and the exit status of a command. The syntax is </p>
<p>while condition<br />
do<br />
     list of commands<br />
done</p>
<p align="justify">As an example, let’s write a script named table that will take a number as a command line argument, and print its ‘times table’. The sample below shows the output we would expect from the script:</p>
<p><code><br />
$ table 5<br />
1 times 5 is 5<br />
2 times 5 is 10<br />
3 times 5 is 15<br />
4 times 5 is 20<br />
5 times 5 is 25<br />
6 times 5 is 30<br />
7 times 5 is 35<br />
8 times 5 is 40<br />
9 times 5 is 45<br />
10 times 5 is 50<br />
11 times 5 is 55<br />
12 times 5 is 60<br />
</code></p>
<p align="justify">To achieve this, we will need a variable that will act as a counter. This will begin at 1 and be incremented within the loop. The loop will keep repeating while the counter is less than 13. Within the loop, we will multiply the command line argument $1 by the counter, display the result of this sum, and increment the counter.</p>
<p>The table script is shown below.</p>
<p><code><br />
counter=1<br />
while [ $counter -lt 13 ]<br />
do<br />
    calc=$(( $counter * $1 ))<br />
    echo $counter times $1 is $calc<br />
    counter=$((  $counter + 1 ))<br />
done<br />
</code></p>
<p align="justify">There are two additional commands that can be used within loops. The break command breaks out of the loop, even though the terminating condition has not yet been met. The continue command goes back to the beginning of the loop without executing any subsequent commands. If the condition controlling the loop is still true, the loop will be repeated. </p>
<p align="justify">A loop can be coded to repeat itself infinitely, using the construct  while true. This can be used for repeated checking of some aspect of the system. Generally, in this kind of loop, the user is given the option to quit the loop, although he can simply terminate it using the interrupt key.</p>
<p align="justify">The following script will display the number of processes which the current user has running, giving him an option to list the processes. He can also opt to quit the script. A delay of 10 seconds is introduced into the loop by using the sleep command that pauses for a given number of seconds.</p>
<p><code><br />
while true<br />
   do<br />
   sleep 10<br />
   set $(ps -u $LOGNAME | wc)<br />
   echo You have $1 processes running<br />
   echo Enter l to list them, q to quit or c to continue<br />
   read u_reply<br />
   if [ $u_reply = q ]<br />
     then<br />
     break<br />
   fi<br />
   if [ $u_reply = c ]<br />
     then<br />
     continue<br />
   fi<br />
   ps -u $LOGNAME<br />
done<br />
</code></p>
<p align="justify">The command set $(ps –u $LOGNAME | wc) lists processes belonging to the current login name and pipes the output to the wc command. This returns the number of words, lines and bytes contained in the answer. This output is used to set the script arguments $1 etc. The first of these arguments, the number of lines returned by the ps command, will be the number of processes this user has running. This is displayed to the user.</p>
<p align="justify">If he chooses to continue without listing the processes, the continue  command returns to the beginning of the loop. If he chooses to quit, the break command breaks out of the loop. Otherwise, the script will carry out he second ps command that lists all the processes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/12/07/the-while-loop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using the set Command</title>
		<link>http://www.linux-bloggersplace.org/2007/12/04/using-the-set-command/</link>
		<comments>http://www.linux-bloggersplace.org/2007/12/04/using-the-set-command/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 19:15:22 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[commands]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/12/04/using-the-set-command/</guid>
		<description><![CDATA[The set command can be used to store a new set of values in the script arguments ($1, $2 etc.).  This can be useful for separating the output from a command into separate components that can be worked with individually. The set command requires a string of arguments separated by spaces.
Suppose we have a [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">The <em>set</em> command can be used to store a new set of values in the script arguments ($1, $2 etc.).  This can be useful for separating the output from a command into separate components that can be worked with individually. The <strong>set command</strong> requires a string of arguments separated by spaces.</p>
<p align="justify">Suppose we have a script that runs at the end of each day, carrying out various tasks. On Fridays only, we want to remove a file named weekhist and create an empty one in its place.</p>
<p align="justify">The date command will tell us the day of the week, but it also gives a lot of other information that is not relevant to this task. The output from the <em>date command</em> looks like this:</p>
<p>Mon Sep 3 18:38:21 GMT 2007</p>
<p>We are only interested in the first column, which tells us the day of the week.</p>
<p align="justify">Placing the output from this command into the <em>script</em> arguments allows us to separate  the output so that we can access the bit we want.</p>
<p>The command:</p>
<p>set $(date)</p>
<p>will have the following effect:</p>
<p>$1 becomes Mon<br />
$2 becomes Sep<br />
$3 becomes 3<br />
$4 becomes 18:38:21<br />
$5 becomes GMT<br />
$6 becomes 2007</p>
<p>We can then check the value of $1 to see if it is a Friday. The relevant section of the script would be:</p>
<p><code><br />
set $(date)<br />
if [ $1 = Fri ]<br />
         then<br />
	   rm weekhist<br />
         touch weekhist<br />
fi<br />
</code></p>
<p align="justify">We could use other portions of the output from date  for other purposes. Suppose that rather than deleting the weekhist file, we want instead to move it to a file named weekhist suffixed by today’s date.</p>
<p>We could change the script as follows:</p>
<p><code><br />
set $(date)<br />
if [ $1 = Fri ]<br />
         then<br />
	   mv weekhist weekhist_$2_$3_$6<br />
         touch weekhist<br />
fi<br />
</code></p>
<p align="justify">If run on Friday September 4 2007, this would have the effect of renaming the old weekhist file to weekhist_Sep_4_2007.</p>
<p align="justify">This technique can be used with any command that gives a single line of output consisting of columns separated by spaces. In a later article, we will look at how to deal with the output from commands that give many lines of output.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/12/04/using-the-set-command/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Providing Input to Commands Within a Script</title>
		<link>http://www.linux-bloggersplace.org/2007/12/04/providing-input-to-commands-within-a-script/</link>
		<comments>http://www.linux-bloggersplace.org/2007/12/04/providing-input-to-commands-within-a-script/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 19:13:39 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[commands]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/12/04/providing-input-to-commands-within-a-script/</guid>
		<description><![CDATA[Scripts should run with as little user intervention as possible. There are several reasons for this. Firstly, the whole point of having a script is to reduce the amount of typing needed to run a job. Secondly, scripts should be able to be run by users with little or no technical knowledge. Thirdly, they are [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Scripts should run with as little user intervention as possible. There are several reasons for this. Firstly, the whole point of having a script is to reduce the amount of typing needed to run a job. Secondly, scripts should be able to be run by users with little or no technical knowledge. Thirdly, they are designed to make sure that nothing is left out or mistyped, thus reducing operator errors.</p>
<p align="justify">Many <em>Unix</em> commands and programs require input from the user. In an automated script, you would often want to provide this information from the script itself. We have seen in an earlier article that the standard input and output can be diverted to a file instead of the terminal by using <strong>output redirection</strong> (>), input redirection (&lt;) and error redirection (2>). </p>
<p align="justify">Input can be redirected to come from the script itself by using the symbols &lt;&lt;. The text to be taken as input must be enclosed in exclamation marks (!). The following example illustrates how this is done.</p>
<p>cat > textfile  &lt;&lt;!<br />
	This is some sample text<br />
!</p>
<p align="justify">Again, this is a feature which can be very useful in installation scripts, which may need to set up initial files, customized scripts for running jobs etc.</p>
<p align="justify">Let’s look at an installation script that needs to schedule a day end job to be run at 6 PM daily. The cron utility is used for job scheduling. cron can take details of the job from a file, or they can be entered from the terminal. In the example below, the information is supplied within the installation script.</p>
<p>cron &lt;&lt;!<br />
00 18 * * * /usr/progs/dayend</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/12/04/providing-input-to-commands-within-a-script/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Case command</title>
		<link>http://www.linux-bloggersplace.org/2007/12/04/the-case-command/</link>
		<comments>http://www.linux-bloggersplace.org/2007/12/04/the-case-command/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 19:12:27 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[commands]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/12/04/the-case-command/</guid>
		<description><![CDATA[In a previous article, we looked at making commands within the script execute only if a given condition is true, using the if&#8230;.else&#8230;fi construct. However, this construct can often become very clumsy when there are several possible conditions to be accounted for. Take the menu script example below:

clear
echo User Menu for $LOGNAME
echo Accounts......................1
echo Star Office...................2
echo [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">In a previous article, we looked at making commands within the script execute only if a given condition is true, using the if&#8230;.else&#8230;fi construct. However, this construct can often become very clumsy when there are several possible conditions to be accounted for. Take the <strong>menu</strong> script example below:</p>
<p><code><br />
clear<br />
echo User Menu for $LOGNAME<br />
echo Accounts......................1<br />
echo Star Office...................2<br />
echo Wages .........................3<br />
echo Exit .............................4<br />
echo<br />
echo Please enter your choice 1,2,3 or 4<br />
read menu_choice<br />
if      [ $menu_choice = 1 ]<br />
         then<br />
         accounts<br />
elif   [ $menu_choice = 2]<br />
         then<br />
         star<br />
elif  [ $menu_choice = 3 ]<br />
         then<br />
         wages<br />
else<br />
        exit<br />
fi<br />
$0<br />
</code></p>
<p align="justify">Here we have four different conditions, all depending on the single variable $menu_choice. If we wanted to add more choices to the menu, it would become even more complex.</p>
<p align="justify">There is a better way of doing this, provided that all the conditions depend on the value of a single variable. This is to use the <em>case</em> construct.</p>
<p><code><br />
clear<br />
echo User Menu for $LOGNAME<br />
echo Accounts......................1<br />
echo Star Office...................2<br />
echo Wages .........................3<br />
echo Exit .............................4<br />
echo<br />
echo Please enter your choice 1,2,3 or 4<br />
read menu_choice<br />
case $menu_choice<br />
in<br />
1) accounts;;<br />
2) star;;<br />
3) wages;;<br />
4) exit;;<br />
*) echo $menu_choice is not a valid option;;<br />
esac<br />
$0<br />
</code></p>
<p align="justify">This new script does exactly the same as the old one, but it is much neater, and much easier to expand if more menu choices are added.</p>
<p align="justify">As with the if&#8230;fi construct, the syntax of the case&#8230;esac construct is very strict. It must begin with the word case followed by the name of the variable whose contents are to be examined. The word in must be placed on a separate line. The expected values must then be listed, each on a separate line followed immediately by the close bracket symbol. After the bracket, there is a space followed by one or more commands to be executed if the variable has this value. A double semi-colon terminates the list of commands.</p>
<p align="justify">The values to be matched may contain wild cards. Thus the *) matches to any value of menu_choice. Any value of menu_choice (e.g. 5 or 6) not previously matched will be seen as a match here. This then causes any value that is not between 1 and 4 to display the error message.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/12/04/the-case-command/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Command Substitution</title>
		<link>http://www.linux-bloggersplace.org/2007/11/30/command-substitution/</link>
		<comments>http://www.linux-bloggersplace.org/2007/11/30/command-substitution/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 08:32:15 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[misc]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/11/30/command-substitution/</guid>
		<description><![CDATA[Normally, when you run a command from a script, the output from the command goes to the standard output: usually the user’s terminal. However, you may want to do further work with the output from the command, or use it to make decisions within the script.
Lets take a simple example. Suppose that you want to [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Normally, when you run a <strong>command</strong> from a <strong>script</strong>, the output from the command goes to the standard output: usually the user’s terminal. However, you may want to do further work with the output from the command, or use it to make decisions within the <em>script</em>.</p>
<p align="justify">Lets take a simple example. Suppose that you want to display the message, “Your current working directory is “  followed by the working directory.  This can be done by inserting the output from the pwd command into the echo command, using a technique known as command substitution. There are two ways of doing this. The first is to enclose the name of the command in back quotes thus: `pwd`. The second is to enclose it in brackets and prefix it with the $ sign as follows: $(pwd).</p>
<p>So the above example could be entered into a <em>script</em> as follows:</p>
<p>echo Your current working directory is $(pwd)</p>
<p align="justify">This facility can be very useful in installation scripts, which may need to install different resources depending on system information such as the type of processor or operating system.</p>
<p>The uname command displays information about the current operating environment. Various switches can be used with it: </p>
<p>-a&nbsp;&nbsp;Display all information<br />
-s&nbsp;&nbsp;Display the name of the operating system<br />
-p&nbsp;&nbsp;Display the type of processor<br />
-r&nbsp;&nbsp;Display the release number of the operating system.</p>
<p>The following is part of a script that uses the name of the operating system to decide which files to install.</p>
<p><code><br />
ins_opsys=$(uname –s)<br />
if [ $ins_opsys = SunOS ]<br />
    then<br />
    tar xvf sunfiles.tar<br />
elif  [ $ins_opsys = UnixWare ]<br />
    then<br />
    tar xvf unixwarefiles.tar<br />
elif  [ $ins_opsys = AIX ]<br />
    then<br />
    tar xvf aixfiles.tar<br />
else<br />
     echo Operating system $ins_opsys not yet supported<br />
fi<br />
</code></p>
<p align="justify">Command substitution becomes even more useful when combined with techniques covered in the next few articles. We will learn how to split the output from the command so that we can use selected parts of it, or reformat it. We will also learn how to deal with multi-line output.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/11/30/command-substitution/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Metacharacters</title>
		<link>http://www.linux-bloggersplace.org/2007/11/30/metacharacters/</link>
		<comments>http://www.linux-bloggersplace.org/2007/11/30/metacharacters/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 08:22:27 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[misc]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/11/30/metacharacters/</guid>
		<description><![CDATA[Certain characters have special meaning to the shell. These are known as metacharacters. They are listed below.
Pattern Matching:
This set of metacharacters is used in pattern matching, also known as wild cards.
*&#160;&#160;&#160;&#160;Match zero or more characters
?&#160;&#160;&#160;&#160;match exactly one character
[]&#160;&#160;&#160;Match a list or range of characters eg [AB], [A-N]
[!]&#160;&#160;Match anything except the list or range of characters [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Certain characters have special meaning to the shell. These are known as metacharacters. They are listed below.</p>
<h3>Pattern Matching:</h3>
<p>This set of metacharacters is used in pattern matching, also known as wild cards.</p>
<p>*&nbsp;&nbsp;&nbsp;&nbsp;Match zero or more characters<br />
?&nbsp;&nbsp;&nbsp;&nbsp;match exactly one character<br />
[]&nbsp;&nbsp;&nbsp;Match a list or range of characters eg [AB], [A-N]<br />
[!]&nbsp;&nbsp;Match anything except the list or range of characters e.g. [!AB]</p>
<h3>Redirection:</h3>
<p>&gt;&nbsp;&nbsp;&nbsp;&nbsp;Redirect away from the standard output file<br />
&gt;&gt;&nbsp;&nbsp;&nbsp;Redirect away from the standard output and append to the target file<br />
2&gt;&nbsp;&nbsp;&nbsp;Redirect away from the standard error file<br />
&lt;&nbsp;&nbsp;&nbsp;&nbsp;redirect away from the standard input file<br />
&lt;&lt;&nbsp;&nbsp;&nbsp;Start of a Here document<br />
|&nbsp;&nbsp;&nbsp;&nbsp;Pipe the output of one command to the input of a second command</p>
<h3>Miscellaneous</h3>
<p>&amp;&nbsp;&nbsp;&nbsp;&nbsp;Run the command in the background<br />
()&nbsp;&nbsp;&nbsp;Execute command(s) in sub-shell<br />
$&nbsp;&nbsp;&nbsp;&nbsp;Substitute the value of a variable or argument<br />
#&nbsp;&nbsp;&nbsp;&nbsp;ignore text to end of line<br />
;&nbsp;&nbsp;&nbsp;&nbsp;New line<br />
:&nbsp;&nbsp;&nbsp;&nbsp;Null command</p>
<h3>Literal</h3>
<p>\&nbsp;&nbsp;&nbsp;&nbsp;take the literal of the following character – this is used to include an actual metacharacter in a string, rather than have the shell try to interpret it e.g.\$<br />
‘’&nbsp;&nbsp;&nbsp;Interpret all characters enclosed in single quotes as a literal<br />
“”&nbsp;&nbsp;&nbsp;Interpret all characters enclosed in double quotes as a literal, except the dollar sign.</p>
<p align="justify">Literals are important, since without them, the shell will first interpret any metacharacters before working with the string. For example, the following command would produce an error:</p>
<p>echo Enter your name&gt;</p>
<p>since the &gt; would be interpreted as a redirection symbol.  This can be avoided by placing the text in quotes:</p>
<p>echo ‘Enter your name&gt;’</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/11/30/metacharacters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Understanding RAID</title>
		<link>http://www.linux-bloggersplace.org/2007/11/17/1understanding-raid/</link>
		<comments>http://www.linux-bloggersplace.org/2007/11/17/1understanding-raid/#comments</comments>
		<pubDate>Sat, 17 Nov 2007 16:40:48 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[RAID]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/11/17/1understanding-raid/</guid>
		<description><![CDATA[The term RAID stands for Redundant Array of Independent Disks. RAID technology allows you to group together the storage capacities of two or more disks, and manage them as a single storage unit. Users are unaware that this array is not a single disk. A RAID array is known as a virtual device, since the [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">The term <strong>RAID</strong> stands for Redundant Array of Independent Disks. <em>RAID technology</em> allows you to group together the storage capacities of two or more disks, and manage them as a single storage unit. Users are unaware that this array is not a single disk. A RAID array is known as a virtual device, since the operating system views it as a single device when storing data.</p>
<p align="justify">RAID can either be controlled at the software or the hardware level. If it is hardware controlled, a <strong>RAID</strong> controller will be supplied. This is a plug-in card that is attached to the motherboard, and the disks are plugged directly into this controller. It controls all RAID activities, so that the motherboard, and the operating system, are not aware that it is anything other than a single disk device. This is a good option for large RAID arrays, since it tends to give better performance.</p>
<p align="justify">When using this option, <strong>RAID devices</strong> are configured into the operating system in exactly the same way as single-unit devices. There are no special configuration considerations.</p>
<p align="justify">If <em>RAID</em> is configured at the software level, partitions are grouped together into a virtual device and appear to higher layers of the operating system as a single unit. This gives good performance under Linux, and is a less expensive option.</p>
<p align="justify">Depending on how it is used, RAID can have several advantages, including increased performance, better fault tolerance and data integrity, and more efficient storage. RAID levels are a way of defining the actual type of RAID configuration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/11/17/1understanding-raid/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting User Limits</title>
		<link>http://www.linux-bloggersplace.org/2007/11/11/setting-user-limits/</link>
		<comments>http://www.linux-bloggersplace.org/2007/11/11/setting-user-limits/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 04:26:20 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[User Management]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/11/11/setting-user-limits/</guid>
		<description><![CDATA[In a large installation, it is sometimes difficult to keep control of user activities. Some user programs can use excessive resources, to the detriment of other users. This is particularly true in universities and colleges, where student’s activities can leave few resources for programs run by staff. Also some services automatically grab as many resources [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">In a large installation, it is sometimes difficult to keep control of user activities. Some user programs can use excessive resources, to the detriment of other users. This is particularly true in universities and colleges, where student’s activities can leave few resources for programs run by staff. Also some services automatically grab as many resources as they find available at run time, leaving few resources for subsequent programs. Resources include disk space, memory, CPU time and I/O requests.</p>
<p align="justify">It can be useful, therefore, to set limits for each user or group of users. The /etc/security directory holds files that can be used to limit user activities. The most important of these files is /etc/security/limits.conf. It holds entries in the following format:</p>
<p>&lt;domain> 	&lt;type> 	&lt;item> 	&lt;value><br />
where<br />
&lt;domain>&nbsp;&nbsp;&nbsp;is the name of the user or group (groups must be prefixed with @)<br />
&lt;type>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is either ‘hard’ or ‘soft’<br />
&lt;item>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is one of the items listed below<br />
&lt;value>&nbsp;&nbsp;&nbsp;&nbsp;is the value required</p>
<p>Items include:<br />
core 		- limits the core file size (KB)<br />
data 		- maximum data size (KB)<br />
fsize 		- maximum filesize (KB)<br />
memlock 		- maximum locked-in-memory address space (KB)<br />
nofile 		- number of open files<br />
rss 			- max resident memory set size (KB)<br />
stack 		- stack size (KB)<br />
cpu 		- maximum CPU time<br />
nproc 		- maximum number of processes<br />
as 			- address space limit<br />
maxlogins 		- maximum number of logins for this user<br />
priority 		- the priority used for user processes<br />
locks 		- maximum number of file locks</p>
<p align="justify">When setting these limits, you should check the documentation of any software packages that you are running, to ensure that they are able to run within the limits that you have set.</p>
<p align="justify">Another useful file in this directory is /etc/security/access.conf, which is used to control which users are allowed to log in from which sources. For example, it is possible to restrict a user’s access to one particular terminal, or to prevent users from logging in via the network.</p>
<p>This file holds entries in the format:</p>
<p>&lt;permission>:&lt;user_or_group>:&lt;origin><br />
where<br />
&lt;permission>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;can be + or -<br />
&lt;user_or_group>&nbsp;A user name, group name, or ALL, or ALL except user or group name<br />
&lt;origin>&nbsp;&nbsp;&nbsp;&nbsp;A TTY number, host name or domain name</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/11/11/setting-user-limits/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Further uses of the Find command</title>
		<link>http://www.linux-bloggersplace.org/2007/11/08/further-uses-of-the-find-command/</link>
		<comments>http://www.linux-bloggersplace.org/2007/11/08/further-uses-of-the-find-command/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 16:42:20 +0000</pubDate>
		<dc:creator>passion@linux</dc:creator>
		
		<category><![CDATA[misc]]></category>

		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linux-bloggersplace.org/2007/11/08/further-uses-of-the-find-command/</guid>
		<description><![CDATA[In another article, we briefly looked at the find command, which searches for specified files. We will now look at more uses of this very powerful command.
It can be used to search for files using various criteria, including name, owner and time last changed. Additionally, it can execute a command or script for each of [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">In another article, we briefly looked at the find command, which searches for specified files. We will now look at more uses of this very powerful command.</p>
<p align="justify">It can be used to search for files using various criteria, including name, owner and time last changed. Additionally, it can execute a command or script for each of the matching files. It could therefore be used for many purposes, for example, to remove files not accessed since a given date, to recompile all programs modified since the time of the last compile, or to backup all the files belonging to a specific user.</p>
<p>The syntax of the command is:</p>
<p>find <starting_directory>  <switch_list>  <criteria><br />
where <starting_directory> is the pathname to the directory where the search is to begin and<br />
<switch_list> and  <criteria> specify the search criteria and any actions to be taken, as detailed below:</p>
<p>-name	Find files whose name matches the given pattern. The pattern should be in quotes.<br />
-print			Display the path of matching files<br />
-user			Find files belonging to a specific user<br />
-exec command {} \;	Execute Unix/Linux command for each matching file.<br />
-atime (+t,-t,t)	Find files accessed more that +t days ago, less than -t or precisely t days ago.<br />
-ctime (+t,-t,t)	Find files changed more that +t days ago, less than -t or precisely t days ago.</p>
<p>-perm			Find files with given permissions.<br />
-type			Locate files of a given type:<br />
c=character device b=blocked device d=directory<br />
p=pipe s=socket f=normal file l=symbolic link<br />
-size nx			Find files with size larger than n where x can be b=bytes;<br />
c=characters; k=kilobytes w=2 byte word:</p>
<p>Examples:</p>
<p>find . –name myfile<br />
Search for myfile under the current directory</p>
<p>find /usr/sam/cprogs –ctime –1 –exec cc {} \;</p>
<p>Compile all programs that have changed less than one day ago.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linux-bloggersplace.org/2007/11/08/further-uses-of-the-find-command/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
