<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unix Sysadmin &#187; Scripting</title>
	<atom:link href="http://www.sysadmindayph.com/blog/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sysadmindayph.com/blog</link>
	<description>SysAdmin Blog, TechTips and Reviews</description>
	<lastBuildDate>Fri, 27 Jan 2012 04:36:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>KSH Script Basics &#124; Special Shell Variables</title>
		<link>http://www.sysadmindayph.com/blog/ksh-script-basics-special-shell-variables/</link>
		<comments>http://www.sysadmindayph.com/blog/ksh-script-basics-special-shell-variables/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 02:57:31 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Commands]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[if else]]></category>
		<category><![CDATA[if else if]]></category>
		<category><![CDATA[ksh shell]]></category>
		<category><![CDATA[ksh shell script]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[special shell variable]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/?p=221</guid>
		<description><![CDATA[Just deleted tons of stale, unsused user accounts. Here are some KSH shell basics and special shell variable. I need to Google them up myself to get reminded that &#8216;$?&#8217; is the output variable for script execution. That is, it&#8217;s 0 for successful execution and 1 if there is any error. Special shell variables There &#8230; <a href="http://www.sysadmindayph.com/blog/ksh-script-basics-special-shell-variables/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Just deleted tons of stale, unsused user accounts. Here are some KSH shell basics and special shell variable. I need to Google them up myself to get reminded that &#8216;$?&#8217; is the output variable for script execution. That is, it&#8217;s 0 for successful execution and 1 if there is any error.</p>
<p><span id="more-221"></span></p>
<p>Special shell variables<br />
There are some variables which are set internally by the shell and which are available to the user:</p>
<p>Name          Description<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
$1 &#8211; $9       these variables are the positional parameters.</p>
<p>$0            the name of the command currently being executed.</p>
<p>$#            the number of positional arguments given to this<br />
              invocation of the shell.</p>
<p>$?            the exit status of the last command executed is<br />
              given as a decimal string.  When a command<br />
              completes successfully, it returns the exit status<br />
              of 0 (zero), otherwise it returns a non-zero exit<br />
              status.</p>
<p>$$            the process number of this shell &#8211; useful for<br />
              including in filenames, to make them unique.</p>
<p>$!            the process id of the last command run in<br />
              the background.</p>
<p>$-            the current options supplied to this invocation<br />
              of the shell.</p>
<p>$*            a string containing all the arguments to the<br />
              shell, starting at $1.</p>
<p>$@            same as above, except when quoted.</p>
<p><strong>Branching</strong><br />
<code>if then fi<br />
if [[ $value -eq 7 ]];then<br />
   print "$value is 7"<br />
fi</code><br />
or:</p>
<p><code>if [[ $value -eq 7 ]]<br />
then<br />
   print "$value is 7"<br />
fi</code>or:</p>
<p><code>if [[ $value -eq 7 ]];then print "$value is 7";fi</p>
<p>if then else fi<br />
if [[ $name = "John" ]];then<br />
   print "Your welcome, ${name}."<br />
else<br />
   print "Good bye, ${name}!"<br />
fi</code></p>
<p><code>if then elif then else fi<br />
if [[ $name = "John" ]];then<br />
   print "Your welcome, ${name}."<br />
elif [[ $name = "Hanna" ]];then<br />
   print "Hello, ${name}, who are you?"<br />
else<br />
   print "Good bye, ${name}!"<br />
fi</code></p>
<p><code>case esac<br />
case $var in<br />
   john|fred) print $invitation;;<br />
   martin)    print $declination;;<br />
   *)         print "Wrong name...";;<br />
esac</code></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p><strong>Looping Command Syntax for Scripts</strong></p>
<p><code>while do done<br />
while [[ $count -gt 0 ]];do<br />
   print "\$count is $count"<br />
   (( count -= 1 ))<br />
done</code><br />
<code>until do done<br />
until [[ $answer = "yes" ]];do<br />
   print -n "Please enter \"yes\": "<br />
   read answer<br />
   print ""<br />
done</code><br />
<code>for var in list do done<br />
for foo in $(ls);do<br />
   if [[ -d $foo ]];then<br />
      print "$foo is a directory"<br />
   else<br />
      print "$foo is not a directory"<br />
   fi<br />
done</code><br />
continue&#8230;break<br />
One can skip the rest of a loop and directly go to the next iteration with: &#8220;continue&#8221;. </p>
<p><code>while read line<br />
do<br />
   if [[ $line = *.gz ]];then<br />
      continue<br />
   else<br />
      print $line<br />
   fi<br />
done</code><br />
One can also prematurely leave a loop with: &#8220;break&#8221;. </p>
<p><code>while read line;do<br />
   if [[ $line = *!(.c) ]];then<br />
      break<br />
   else<br />
      print $line<br />
   fi<br />
done</code></p>
<p>http://www.well.ox.ac.uk/~johnb/comp/unix/ksh.html</p>
<p>Removing accounts from predefine list:</p>
<p><code>#!/bin/ksh</p>
<p>for each in `cat ./list-a`<br />
do<br />
  grep -i $each  /etc/passwd<br />
    if [[ $? -eq 1 ]]; then<br />
        echo "$each does not exists."<br />
        sleep 2<br />
        continue;<br />
    else<br />
        echo "$each exists"<br />
        echo "Deleting account.. "<br />
        sleep 2<br />
        userdel $each<br />
        echo "$each deleted"<br />
        sleep 5<br />
     fi</p>
<p>done</code></p>
<p>Or course, the sleep there is just for aesthetic.. I want to see the screen</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/ksh-script-basics-special-shell-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UNIX One-Liners: Some Useful Shell Programs</title>
		<link>http://www.sysadmindayph.com/blog/unix-one-liners-some-useful-shell-programs/</link>
		<comments>http://www.sysadmindayph.com/blog/unix-one-liners-some-useful-shell-programs/#comments</comments>
		<pubDate>Sat, 23 May 2009 05:57:58 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Script]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Sysadmin Mag]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Volume 1]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ksh]]></category>
		<category><![CDATA[one liner]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell program]]></category>
		<category><![CDATA[shell scripts]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/?p=152</guid>
		<description><![CDATA[My Favorite One-Liners: Some Useful Shell Programs&#8230; But first things first&#8230; I would like to note that this aint my list of favorite shell programs.. well, it has become&#8230; but what I mean is this aint an original article that I created and posted here.. this is a section from the now defunt, Sysadmin Magazine&#8230; &#8230; <a href="http://www.sysadmindayph.com/blog/unix-one-liners-some-useful-shell-programs/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p><strong>My Favorite One-Liners: Some Useful Shell Programs</strong>&#8230; But first things first&#8230; I would like to note that this aint my list of favorite shell programs.. well, it has become&#8230; but what I mean is this aint an original article that I created and posted here.. this is a section from the now defunt, <strong>Sysadmin Magazine</strong>&#8230; and you&#8217;ll be reading a lot of those here&#8230;.</p>
<p>&#8220;Keep It Simple, SysAdmin,&#8221;  or perhaps just &#8220;Keep It Shell Script&#8221;, that is one of the motto that every sysdamin knows&#8230; They automate, they script, they relax.</p>
<p>Too many system administrators, especially former or frustrated programmers, get involved and distracted creating ad hoc programs that grow until they have a life and a following of their own. These programs generally are written in C, awk, or C shell, have no documentation, and are incomprehensible, even to the author, less than two weeks after being finished. </p>
<p><span id="more-152"></span></p>
<p>While it&#8217;s no cure-all for bad programming practices, I prefer to write simple shell scripts for system administration work. How simple are they? Simple enough that their inner workings should be almost obvious; tricky programs are fine for impressing your friends but hard to understand when the system has to be restored at 3:00 A.M. And of course, the C shell is so much more elegant, but not every system has one, which means that C shell programs aren&#8217;t portable. What price elegance?</p>
<p>My own pride is in writing programs that can be easily understood, even if they aren&#8217;t perfect. In fact, I&#8217;m sure I will get at least five pieces of email for each of these programs, showing how they can be improved. If you like being tricky, find ingenious things to do with your programs after you write them. If these programs are beyond you, don&#8217;t despair: but don&#8217;t fail to read the manual pages for the shell and every command you don&#8217;t understand. Meanwhile, they don&#8217;t get much simpler than Tail:</p>
<p>for i in $*<br />
do<br />
echo &#8220;=========&#8221;  $i  &#8220;==========&#8221;<br />
tail $i<br />
done</p>
<p>Tail emulates the behavior of the head command when presented with multiple files, instead of the binary tail&#8217;s default behavior of just showing you the tail of one file. The simple for-do-done loop executes the echo and tail commands repeatedly on whatever files you specify on the command line.</p>
<p><strong>Take Four, They&#8217;re Small<br />
</strong><br />
While we&#8217;re on incredibly simple programs, how many times have you had to double-space a file and forgotten how? It happened to me every time, until I wrote double:</p>
<p>pr -dt $*</p>
<p>See? Most of the work is just picking a good name for the program. In the same vein, here&#8217;s another self-documenting program called crtolf:</p>
<p>tr &#8220;\015&#8243; &#8220;\012&#8243;</p>
<p>Here, I had to surround the arguments to the tr program with double quotes to prevent the shell from hiccupping on the backslash, which serves to indicate to tr that the argument is an octal constant (in this case, the octal representations of the carriage return and linefeed characters).</p>
<p>I&#8217;m sure you&#8217;d sometimes like to know which files are taking up the most space in a particular overstuffed directory, so here&#8217;s largest:</p>
<p>ls -l $* | sort -r -n +4 -5</p>
<p>Since the ls -l command shows the file size in the fifth whitespace-delimited column, the arguments +4 -5 tell sort that&#8217;s the column you want to look at. The -n flag tells sort to consider the full numerical value of the numbers in that column. Without this precaution, the single digit 9 would be sorted after 1111111, since 1 is lower in the ASCII collating sequence. Finally, the -r flag reminds sort to present the lines in reverse sequence, since it&#8217;s the largest numbers we&#8217;re most interested in here.</p>
<p>And how about a program to help you create these little one-line programs?</p>
<p>if test -f $1<br />
then echo $0: cannot overwrite existing file $1<br />
exit 1<br />
fi<br />
cat  $1 ; chmod 755 $1<br />
exit 0</p>
<p>To use mkcmd, above, simply type mkcmd filename, then the shell program you want to enter, followed by a single Control-D. The program does the rest.</p>
<p><strong>Testing, Testing<br />
</strong><br />
Mkcmd introduces rudimentary error checking to these short programs. In cases like these, some error checking is necessary, but more might be overkill for what&#8217;s essentially a one-line program. Why didn&#8217;t I check to make sure that at least the filename argument is typed on the command line? Leave out the filename, and the test program itself will complain:</p>
<p>mkcmd: test: argument expected</p>
<p>Clearly, this is minimalist thinking. But it alerts you to the problem, so why bother getting much fancier?</p>
<p>Testing can be done for other reasons than error checking. Sometimes you want to perform a function depending on what tty line a user is logging in on, or what system they&#8217;re on. The program fragment in Listing 1 from the end of a Korn shell .profile is a good illustration. The first section grabs the name of the system the .profile is running on (by running the uname command), and stuffs it into the SYS variable. That string is then used, together with the value of PWD (kept up-to-date by the Korn shell), to make the shell prompt reflect the system, current directory, and command number that the user is working with. When you set a shell variable, you simply name it; when you use its actual value, you have to prefix it with a $ character.</p>
<p>But wait, there&#8217;s more! A similar technique extracts the actual name of the tty line, using sed to remove its /dev/ prefix (note the use of semicolons as delimiters, since the normal slashes would prove confusing here). The case statement is then used to select a specific series of commands as the final step in the login procedure.</p>
<p>Note the special handling of tty1A, to which a modem is connected for dialins from a laptop computer. This section cuts the normal 25-line display down to 24 (for compatibility with a larger number of terminal programs), and starts a program that will automatically log out the user (thus regaining the port) after five minutes of inactivity. A subsequent section handles a tty name beginning with the string ttyp (a pseudo tty which signifies rlogin or telnet from another machine on the network) by displaying an appropriate message as a reminder. This is also an example of recycling the use of the SYS variable already created. And not a single line of this has to be changed to use it on another computer (except perhaps the hardware-specific tty numbers)!</p>
<p><strong>I&#8217;m a Back-Quote Man</strong></p>
<p>If you&#8217;re not conversant with the back quotes (accent grave) used in Listing 1, read the manual page for your favorite shell carefully. You can usually find the details in a section titled &#8220;Command Substitution.&#8221; Surrounding a command by back quotes effectively puts the results of running that command on the command line, as if you had typed it yourself.</p>
<p>This little one-liner almost breaks all my own rules, because it&#8217;s not immediately apparent what it&#8217;s good for, but it&#8217;s neat and a good illustration of how useful back quotes can be. It&#8217;s called kind:</p>
<p>file * | grep $1 | sed &#8216;s/:.*$//&#8217;</p>
<p>Kind looks for a specific type of file (that you supply on the command line) using the file command, then selects the type you want with grep and removes file&#8217;s extraneous comments with sed. You generally use kind, along with back quotes, when you want a command to operate only on, say, text files:</p>
<p>$ cd /usr/local/bin<br />
$ more `kind text`</p>
<p>These two lines let you look at all your locally produced shell programs (like this one), while not cluttering up your screen with garbage from binary executable files.</p>
<p>While we&#8217;re on back quotes, let&#8217;s try another one-liner. I call this one lsbin:</p>
<p>/bin/ls -1 `echo $PATH | tr &#8220;:&#8221; &#8221; &#8220;`</p>
<p>Lsbin dynamically reads your current PATH environment variable, removes the colons, then feeds the result to ls as simply a list of directories. The final result is a list of all the programs in your PATH, on which you can then run sort, grep, or whatever you wish.<br />
<strong><br />
The More the Merrier</strong></p>
<p>Now let&#8217;s combine back quotes, test, and if-then-else. The program /usr/local/colors, referred to in the .profile in Listing 1, provides an easy-to-follow example:</p>
<p>SYSTEM=`uname -n`<br />
if [ $SYSTEM = "tegu" ]<br />
then<br />
setcolor yellow brown<br />
setcolor -r yellow red<br />
setcolor -g yellow lt_magenta<br />
else<br />
setcolor yellow blue<br />
setcolor -r red lt_magenta<br />
setcolor -g cyan lt_blue<br />
fi</p>
<p>Here I&#8217;m simply picking one color scheme or another, so I can instantly tell which system I&#8217;m working with on a crowded X Window display (note: neither the author or publisher is responsible for eye or brain damage resulting from your use of these colors). I thought the &#8220;bracket&#8221; version of the test command looked better here; it works exactly the same as using the word test.</p>
<p>The following program, which I call arcmail, is a little bit more complicated, but illustrates more of the ways you can combine these simple programming techniques, yet still come up with a readable program. The program moves old email correspondence into a &#8220;holding directory,&#8221; then, if the mail is not examined within 10 days, puts it into a compressed archive file. Arcmail is run every night by cron:</p>
<p>OLDMAIL=&#8221;/ips/david/Mail/old-mail&#8221;<br />
cd $OLDMAIL<br />
FILES=`find . -mtime +190 -print`<br />
if [ "$FILES" ]<br />
then /usr/lbin/arc m Oldmail.arc $FILES<br />
fi<br />
cd ..<br />
FILES=`find . -mtime +180 -print`<br />
if [ "$FILES" ]<br />
then mv $FILES $OLDMAIL<br />
fi</p>
<p>The first thing I do is define the location of the holding directory. This makes it much easier to edit the program later (without causing inadvertent errors) if the particular directory you&#8217;re using happens to change.</p>
<p>Lines 2 and 3 establish the holding directory as a starting point, by cding to it, then running a find in back quotes to determine which, if any, files there meet the age criteria (6 months old, plus 10 days). The (bracketed) test on line 4 is neat: if no filenames were found, the test fails and we skip to the next routine. Otherwise, those same names are used as a command line parameter (on line 5) to the arc command, where the files are added into the archive.</p>
<p>In either case, line 7 brings us up one directory, to the place where current mail is stored. Using back quotes, we again store filenames matching our criteria into a variable called FILES. Notice, though, that the number of days is now exactly 180. If any files 180 days old (or more) are found, they&#8217;re moved to the holding directory OLDMAIL.</p>
<p>The program had to be written &#8220;backwards&#8221; this way because the find command checks the files in the current directory &#8212; and also in all subdirectories. Since the holding directory was a subdirectory of the main mail directory, those older files had to be removed first (which was effectively accomplished by archiving them). Finishing the program by moving the 180-day files to the holding directory ensures that that&#8217;s where they&#8217;ll be in 10 more days, when it will be their turn to be archived.<br />
<strong><br />
Don&#8217;t Stay Lost</strong></p>
<p>Every system administrator runs fsck, and every once in awhile, you discover, to your horror, that you are wasting a couple of precious megabytes of disk space on files that you didn&#8217;t even know you had. To clean out your lost+found directories on a regular basis, simply run checklost as often as you deem advisable, via cron, and mail the results to yourself:</p>
<p>for i in / /usr/spool /ips<br />
do<br />
ls -lta $i/lost+found<br />
echo That was the $i file system<br />
echo &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8221;<br />
done</p>
<p>Naturally, replace my file system names with yours in the first line. Don&#8217;t wipe all the files out by reflex, either; take a look at them and see if they look useful. I once found a header file &#8212; needed to rebuild the kernel &#8212; in a lost+found directory after a crash!</p>
<p>About the Author</p>
<p>David Fiedler is a writer and consultant specializing in UNIX and networking topics. He was the co-author of the first book on UNIX system administration, and can be reached at david@infopro.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/unix-one-liners-some-useful-shell-programs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Increment a (Bash/Korn) Variable</title>
		<link>http://www.sysadmindayph.com/blog/how-to-increment-a-bashkorn-variable/</link>
		<comments>http://www.sysadmindayph.com/blog/how-to-increment-a-bashkorn-variable/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 06:32:02 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[korn]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/?p=114</guid>
		<description><![CDATA[Ever wonder how to increment a number inside a variable in a bash or korn shell? If you&#8217;re the geeky type of guy, I&#8217;m sure you know how.. Well, this quick post is sort of like a note to self.. I jsut want to have it handy in case I need it again.. and for &#8230; <a href="http://www.sysadmindayph.com/blog/how-to-increment-a-bashkorn-variable/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Ever wonder how to increment a number inside a variable in a bash or korn shell? If you&#8217;re the geeky type of guy, I&#8217;m sure you know how..</p>
<p>Well, this quick post is sort of like a note to self.. I jsut want to have it handy in case I need it again.. and for sure, I will need it again..</p>
<p>Anyway, hours are spent searching for the correct format or syntax on the variable, so here it is:</p>
<p>while [[ $NUMBER != $CNTR1 ]]<br />
do<br />
# Separation.. one file each line<br />
#<br />
head -$CNTR1 list | tail -1 &gt; ./processing/$FILENAME.$CNTR1</p>
<p># moved (or copy) &#8216;feedme&#8217; as &#8216;list&#8217;<br />
cp ./processing/$FILENAME.$CNTR1 ./processing/list</p>
<p>## ADD the &#8216;t&#8217; and &#8216;x&#8217; logic here<br />
##<br />
awk &#8216;{print $1}&#8217; ./processing/list &gt; ./processing/cutfile<br />
ACCT=`cut -c1 ./processing/cutfile`<br />
if [ $ACCT !=  1 ]<br />
then<br />
PREFIX=&#8217;t&#8217;<br />
else<br />
PREFIX=&#8217;x&#8217;</p>
<p>fi<br />
UID=`awk &#8216;{print $1}&#8217; ./processing/list`<br />
echo &#8220;UID is $PREFIX$UID&#8221;<br />
NAME=`awk &#8216;{print $2}&#8217; ./processing/list`<br />
cat ./processing/list<br />
echo $PREFIX<br />
## END OF T and X Logic</p>
<p>## CHECK if user exists or not<br />
## If New User, Create it<br />
##<br />
cat /etc/passwd | grep $UID<br />
return=$?<br />
if [ $return = 0 ]<br />
then<br />
echo &#8220;User account already exist&#8221;<br />
exit<br />
else<br />
useradd -d $HOMEDIR$PREFIX$UID -g $GROUPMEM -G $SUPGROUP -s $USERSHELL -c &#8220;$COMMENTS$NAME `date &#8216;+%d%b%y&#8217;`&#8221; -m $PREFIX$UID<br />
#echo $HOMEDIR$PREFIX$UID $GROUPMEM -G $SUPGROUP -s $USERSHELL -c &#8220;$COMMENTS$NAME `date &#8216;+%d%b%y&#8217;`&#8221;   -m  $PREFIX$UID<br />
echo &#8220;$PREFIX$UID:telus2009&#8243; | chpasswd<br />
#echo &#8220;$PREFIX$UID:telus2009&#8243;<br />
echo &#8220;Let&#8217;s continue&#8221;<br />
fi<br />
<strong> <span style="color: #ff0000;"> CNTR1=$(($CNTR1+1))</span></strong><br />
sleep 1<br />
done</p>
<p>It&#8217;s the bold and red text&#8230; Hope it helps someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/how-to-increment-a-bashkorn-variable/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Shell Scripts Tutorials</title>
		<link>http://www.sysadmindayph.com/blog/shell-scripts-tutorials/</link>
		<comments>http://www.sysadmindayph.com/blog/shell-scripts-tutorials/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 03:22:33 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shell scripts]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/?p=85</guid>
		<description><![CDATA[I&#8217;m thinking of doing a series of post that will talk about Shell Scripting, scripting tutorial, examples, application&#8230; the whole nine yards of Unix/Linux shell scripts/programming. The topic of shell scripting is a very broad topic and posting one super long post here will take me all day.. or weeks, depending on my mood. and &#8230; <a href="http://www.sysadmindayph.com/blog/shell-scripts-tutorials/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m thinking of doing a series of post that will talk about <a title="shell scripts" href="http://www.sysadmindayph.com/blog/shell-scripts-tutorials/">Shell Scripting</a>, scripting tutorial, examples, application&#8230; the whole nine yards of <strong>Unix/Linux shell scripts/programming</strong>.</p>
<p>The topic of shell scripting is a very broad topic and posting one super long post here will take me all day.. or weeks, depending on my mood. <img src='http://www.sysadmindayph.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  and internet searches.</p>
<p>So, this will be the start of a series of post about Shell scripts and shell programming. Every new post about scripting will be placed below, with link to the appropriate post.</p>
<p>And did a trend search for shell programming, shell scripts, shell tutorial and it&#8217;s alright. Though the volume of searches has been decreasing but that&#8217;s alright. There are still some.</p>
<p>Perfect!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/shell-scripts-tutorials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Used Another &#8216;For&#8230; DO&#8217; Loop</title>
		<link>http://www.sysadmindayph.com/blog/used-another-for-do-loop/</link>
		<comments>http://www.sysadmindayph.com/blog/used-another-for-do-loop/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 09:52:57 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Commands]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[for loop]]></category>
		<category><![CDATA[while loop]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/?p=81</guid>
		<description><![CDATA[The last post, was used to chmod a list of home directory. I used another application for that &#8216;for..do&#8217; loop again&#8230; it&#8217;s climbing my favorite script command list.. second only to &#8216;while&#8230;do&#8217;.. for X in `ls -last &#124; grep 2006 &#124; awk &#8216;{print $9}&#8217;` do rm -rf $x done bye bye 2006 directories!]]></description>
			<content:encoded><![CDATA[<p>The last post, was used to <a title="for..loop" href="http://www.sysadmindayph.com/blog/looping-through-a-list-of-arguments-bourne/">chmod a list of home directory</a>.</p>
<p>I used another application for that &#8216;for..do&#8217; loop again&#8230; it&#8217;s climbing my favorite script command list.. <img src='http://www.sysadmindayph.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  second only to &#8216;while&#8230;do&#8217;.. <img src='http://www.sysadmindayph.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>for X in `ls -last | grep 2006 | awk &#8216;{print $9}&#8217;`<br />
do<br />
rm -rf $x<br />
done</p>
<p>bye bye 2006 directories!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/used-another-for-do-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Looping Through a List of Arguments (bourne)</title>
		<link>http://www.sysadmindayph.com/blog/looping-through-a-list-of-arguments-bourne/</link>
		<comments>http://www.sysadmindayph.com/blog/looping-through-a-list-of-arguments-bourne/#comments</comments>
		<pubDate>Fri, 30 May 2008 19:53:36 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bourne script]]></category>
		<category><![CDATA[for loop]]></category>
		<category><![CDATA[shell script]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/?p=80</guid>
		<description><![CDATA[The Bourne shell for loop looks like this: for arg in list do ...Handle $arg... done Real life application.. # ls -l &#124; awk &#8216;{print$9}&#8217; user01 user02 user03 user04 user05 user06 user07 user08 user09 # pwd /home # for x in `ls -l &#124; awk &#8216;{print$9}&#8217;` &#62; do &#62; chown $x $x &#62; done # &#8230; <a href="http://www.sysadmindayph.com/blog/looping-through-a-list-of-arguments-bourne/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>The Bourne shell <em>for</em> loop looks like this:</p>
<pre>    for arg <em>in list</em>
do
...<em>Handle $arg</em>...
done</pre>
<p>Real life application.. <img src='http://www.sysadmindayph.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p># ls -l | awk &#8216;{print$9}&#8217;</p>
<p>user01<br />
user02<br />
user03<br />
user04<br />
user05<br />
user06<br />
user07<br />
user08<br />
user09<br />
# pwd<br />
/home<br />
# for x in `ls -l | awk &#8216;{print$9}&#8217;`<br />
&gt; do<br />
&gt; chown $x $x<br />
&gt; done<br />
# ls -aslt<br />
total 136</p>
<p>.. yeah you know what the output is.. <img src='http://www.sysadmindayph.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/looping-through-a-list-of-arguments-bourne/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Store a file output in a variable</title>
		<link>http://www.sysadmindayph.com/blog/store-a-file-output-in-a-variable/</link>
		<comments>http://www.sysadmindayph.com/blog/store-a-file-output-in-a-variable/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 19:00:17 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/store-a-file-output-in-a-variable/</guid>
		<description><![CDATA[draft&#8230;&#8230;. note to self #!/bin/bash -x FILE=&#8221;/tmp/IAP_sched&#8221; DIR=&#8221;/PRA/prod/files/nz/area11/logs/&#8221; FILE2=$(awk &#8216;{ print $1 }&#8217; $FILE) echo &#8220;*** Nameserver IP ***&#8221; for ip in $FILE2 do echo &#8220;Doing GTL on&#8221; $ip /PRA/prod/scripts/arc/get_log_times *$ip* &#62;&#62; /tmp/output.txt done *alias command is not recognize.. hence the full path of &#8216;glt&#8217;]]></description>
			<content:encoded><![CDATA[<p> <em>draft&#8230;&#8230;. note to self<br />
</em></p>
<p>#!/bin/bash -x<br />
FILE=&#8221;/tmp/IAP_sched&#8221;<br />
DIR=&#8221;/PRA/prod/files/nz/area11/logs/&#8221;<br />
FILE2=$(awk &#8216;{ print $1 }&#8217; $FILE)<br />
echo &#8220;*** Nameserver IP ***&#8221;<br />
for ip in $FILE2<br />
do<br />
echo &#8220;Doing GTL on&#8221; $ip<br />
/PRA/prod/scripts/arc/get_log_times  *$ip* &gt;&gt; /tmp/output.txt<br />
done</p>
<p>*alias command is not recognize.. hence the full path of &#8216;glt&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/store-a-file-output-in-a-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loop Kill Mutiple PID On Bourne Shell</title>
		<link>http://www.sysadmindayph.com/blog/loop-kill-mutiple-pid-on-bourne-shell/</link>
		<comments>http://www.sysadmindayph.com/blog/loop-kill-mutiple-pid-on-bourne-shell/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 17:52:23 +0000</pubDate>
		<dc:creator>elizar</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.sysadmindayph.com/blog/loop-kill-mutiple-pid-on-bourne-shell/</guid>
		<description><![CDATA[Just want to document it here. A colleague request to kill multiple PID owned by different users. They don&#8217;t have any special privilege to kill process other than their own. Here&#8217;s a simple for&#8230;loop script that will look for and kill each PID it found. #!/bin/sh -x ps -ef &#124; grep nobody &#124; awk &#8216;{print &#8230; <a href="http://www.sysadmindayph.com/blog/loop-kill-mutiple-pid-on-bourne-shell/">Continue reading</a>]]></description>
			<content:encoded><![CDATA[<p>Just want to document it here. A colleague request to kill multiple PID owned by different users. They don&#8217;t have any special privilege to kill process other than their own.</p>
<p>Here&#8217;s a simple <em>for&#8230;loop</em> script that will look for and kill each PID it found.</p>
<blockquote><p> #!/bin/sh -x<br />
ps -ef | grep nobody | awk &#8216;{print $2}&#8217; &gt; /tmp/PID<br />
filePID=&#8221;/tmp/PID&#8221;<br />
for PID in `cat $filePID`<br />
do<br />
kill -9 $PID<br />
done<br />
#</p></blockquote>
<p>Line 1, tells which shell will execute the script</p>
<p>Line 2, gets all the PID to be killed and store them on a file.</p>
<p>Line 3, assigns a variable for the file</p>
<p>Line 4 to 7 is the for&#8230;do loop which basically gets each line on the file, store the value on $PID and then kill whatever value is in it on line 6.</p>
<p>Yucky script. Post a better one.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sysadmindayph.com/blog/loop-kill-mutiple-pid-on-bourne-shell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

