<?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>Admon Home &#187; shell</title>
	<atom:link href="http://www.admon.org/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.admon.org</link>
	<description>Linux System Administration</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:24:20 +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>Explained Awk1line and Sed1line</title>
		<link>http://www.admon.org/explained-awk1line-and-sed1line/</link>
		<comments>http://www.admon.org/explained-awk1line-and-sed1line/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 14:13:09 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=496</guid>
		<description><![CDATA[If you have ever been interested in awk and sed Unix commands, then you probably know about the awk1line.txt and sed1line.txt files that are floating around the Internet. Each file contains around 80 idiomatic sed and awk one-liners for performing various text modification tasks. Peteris Krumin wrote some articles explaining every one-liner in the two [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever been interested in awk and sed Unix commands, then you probably know about the <a href="http://www.pement.org/awk/awk1line.txt">awk1line.txt</a> and <a href="http://student.northpark.edu/pemente/sed/sed1line.txt">sed1line.txt</a> files that are floating around the Internet. Each file contains around 80 idiomatic sed and awk one-liners for performing various text modification tasks.<span id="more-496"></span></p>
<p>Peteris Krumin wrote some articles explaining every one-liner in the two files, and these articles are absolutely worth a comprehensive read. It took Peteris some months to finish the explaination, thanks a lot to his dedicated work!</p>
<p><strong>The Awk One-Liners Explained article</strong></p>
<ul>
<li> Part One: <a href="http://www.catonmat.net/blog/awk-one-liners-explained-part-one/">File spacing, Numbering and calculations</a></li>
<li> Part Two: <a href="http://www.catonmat.net/blog/awk-one-liners-explained-part-two/">Text conversion and substitution</a></li>
<li> Part Three: <a href="http://www.catonmat.net/blog/awk-one-liners-explained-part-three/">Selective printing or deleting of certain lines</a></li>
<li> Part Four: <a href="http://www.catonmat.net/blog/update-on-famous-awk-one-liners-explained/">String creation, array creation and update on selective printing of certain lines</a></li>
</ul>
<p><strong>The Sed One-Liners Explained article</strong></p>
<ul>
<li> Part One: <a href="http://www.catonmat.net/blog/sed-one-liners-explained-part-one/">File spacing, Numbering and Text conversion and substitution</a></li>
<li> Part Two: <a href="http://www.catonmat.net/blog/sed-one-liners-explained-part-two/">Selective printing of certain lines</a></li>
<li> Part Three: <a href="http://www.catonmat.net/blog/sed-one-liners-explained-part-three/">Selective deletion of certain lines and Special applications</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/explained-awk1line-and-sed1line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoid script running multiple times by file lock</title>
		<link>http://www.admon.org/avoid-script-running-multiple-times-by-file-lock/</link>
		<comments>http://www.admon.org/avoid-script-running-multiple-times-by-file-lock/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 03:42:49 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[filelock]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=361</guid>
		<description><![CDATA[Sometimes we need a single instance of a script to run at a time. Meaning, the script itself should detects whether any instances of himself are still running and act accordingly. When multiple instances of one script running, it&#8217;s easy to cause problems. I&#8217;ve ever seen that about 350 instances of a status checking script [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need a single instance of a script to run at a time. Meaning, the script itself should detects whether any instances of himself are still running and act accordingly.</p>
<p>When multiple instances of one script running, it&#8217;s easy to cause problems. I&#8217;ve ever seen that about 350 instances of a status checking script running there without doing anything, but eat lots of system resource.<br />
<span id="more-361"></span></p>
<p>So it&#8217;s an important feature for your scripting work, and you might have faced similar issues already in cron jobs, system monitoring scripts or system backup procedures.</p>
<p><strong>Well, how can we get rid of such problems?</strong></p>
<p>The idea is simple, the first instance of the script should open a file, and<a title="file lock" href="http://en.wikipedia.org/wiki/File_locking" target="_blank"> lock it to get rid of the second instance</a>. Therefore when the consequent instances try to run and lock the file, it will fails. Here we show three examples on how to lock a script in Shell, Python and Perl. If you have any questions on implementing, please dont hesitate to ask questions at <a title="linux scritping forum" href="http://forum.admon.org/linux-scripting/" target="_blank">our scripting support forum</a>.</p>
<p><strong>How can we create a lock file in Shell?</strong></p>
<p>An example looks like this:</p>
<pre># This is to examine whether the lockfile existed
[ -f "${0}.lock" ] &amp;&amp; exit -1
# Create the lock file
lockfile ${0}.lock
# Your code goes here!
# Release the lock file manually
rm -f ${0}.lock</pre>
<p>Please keep in mind that as we use relative path for the lockfile here, we need to make sure when creating and deleting the lock file, we&#8217;re in the same working directory.</p>
<p><strong>How can we create a lock file in Perl?</strong></p>
<p>With the help of <a href="perldoc.perl.org/functions/fcntl.html" target="_blank">Fcntl</a>, it&#8217;s easy. By default Fcntl is installed on common linux distributions. An example looks like this:</p>
<pre>use Fcntl ':flock'; # import LOCK_* constants
INIT{
open  *{0}
or die "What!? $0:$!";
flock *{0}, LOCK_EX|LOCK_NB
or die "$0 is already running somewhere!n";
}</pre>
<p>It has one disadvantage that on at least one system and on one version of Perl (AS635 on Win2k) you won&#8217;t see any error message or script generated message as Perl will fail (quietly!?) if you try to run the script while it is already running.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/avoid-script-running-multiple-times-by-file-lock/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Difference between login shell and non-login shell</title>
		<link>http://www.admon.org/difference-between-login-shell-and-non-login-shell/</link>
		<comments>http://www.admon.org/difference-between-login-shell-and-non-login-shell/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 13:20:43 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Hardwares]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.admon.org/?p=127</guid>
		<description><![CDATA[Understanding the distinction between your shell types, profile files and shell rc files is important because when you apply modifications to your system you need to know where  to set variables in order to make sure that they can be initialized as expected. Let&#8217;s give a quick answer for this topic which covers the exact [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Understanding the distinction between your <strong>shell types</strong>, profile files and shell rc files is important because when you apply modifications to your system you need to know where  to set variables in order to make sure that they can be initialized as expected.<span id="more-127"></span></p>
<p>Let&#8217;s give a quick answer for this topic which covers the exact difference between the two shells.</p>
<p>When you login your system and see the command line prompt, it&#8217;s a login shell, and it executes these files in order:</p>
<ul>
<li>/etc/profile</li>
<li>~/.bash_profile</li>
<li>~/.bashrc</li>
<li>/etc/bashrc</li>
</ul>
<p>A non-login shell will only execute the two files in order:</p>
<ul>
<li>/etc/bashrc</li>
<li>~/.bashrc</li>
</ul>
<p>So what&#8217;s a non-login shell?<br />
When issuing this command:</p>
<p>$ ssh <a href="mailto:joseph@howto.admon.org">joseph@howto.admon.org</a> &#8216;uptime&#8217;</p>
<p>you will gain a non-login shell at the remote side howto.admon.org. when you type bash after login, your new shell is also a non-login shell.</p>
<p>Now, you may have a clear answer to a common system administration question: <strong>How can I properly apply a new system variable like JAVA_HOME</strong>?</p>
<p>It&#8217;s better to set it in /etc/bashrc other than /etc/profile. Addtionally, there&#8217;re better choice. If you prefer to <strong>make your system clean and tidy</strong>, it&#8217;s suggested to <strong>create single config files in /etc/profile.d</strong>, the point is all these file would be initialized by both login shell and non-login shell:</p>
<p>$ grep profile /etc/profile /etc/bashrc<br />
/etc/profile:# /etc/profile<br />
/etc/profile:for i in /etc/profile.d/*.sh ; do<br />
/etc/bashrc:# Environment stuff goes in /etc/profile<br />
/etc/bashrc:        for i in /etc/profile.d/*.sh; do</p>
<p>NOTE: The suffix of the file name should be &#8220;.sh&#8221;, e.g. /etc/profile.d/java.sh</p>
<p>Further readings: <a href="http://learnlinux.tsf.org.za/courses/build/shell-scripting/ch02s02.html" target="_blank">learnlinux.tsf.org.za</a> and <a href="http://www.linuxquestions.org/questions/linux-general-1/difference-between-normal-shell-and-login-shell-14983/" target="_blank">linuxquestions.org</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/difference-between-login-shell-and-non-login-shell/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>SysAdmin Tips: Bash Shell Shortcuts</title>
		<link>http://www.admon.org/sysadmin-tips-bash-shell-shortcuts/</link>
		<comments>http://www.admon.org/sysadmin-tips-bash-shell-shortcuts/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 08:02:12 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.admon.org/?p=49</guid>
		<description><![CDATA[Bash, which is the default shell in Linux contains a whole lot of key bindings which makes it really easy to use  The most commonly used shortcuts are listed below: Original version of this post is here at blogspot.com. ____________CTRL Key Bound_____________ Ctrl + a &#8211; Jump to the start of the line Ctrl + [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Bash, which is the default shell in Linux contains a whole lot of key bindings which makes it really easy to use  The most commonly used shortcuts are listed below:<br />
Original version of this post is <strong><a href="http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html">here</a></strong> at blogspot.com.</p>
<p><span id="more-49"></span><a title="http://linuxhelp.blogspot.com" href="http://linuxhelp.blogspot.com/"></a><strong></strong></p>
<p><strong>____________CTRL Key Bound_____________</strong><br />
Ctrl + a &#8211; Jump to the start of the line<br />
Ctrl + b &#8211; Move back a char<br />
Ctrl + c &#8211; Terminate the command<br />
Ctrl + d &#8211; Delete from under the cursor<br />
Ctrl + e &#8211; Jump to the end of the line<br />
Ctrl + f &#8211; Move forward a char<br />
Ctrl + k &#8211; Delete to EOL<br />
Ctrl + l &#8211; Clear the screen<br />
Ctrl + r &#8211; Search the history backwards<br />
Ctrl + R &#8211; Search the history backwards with multi occurrence<br />
Ctrl + u &#8211; Delete backward from cursor<br />
Ctrl + xx &#8211; Move between EOL and current cursor position<br />
Ctrl + x @ &#8211; Show possible hostname completions<br />
Ctrl + z &#8211; Suspend/ Stop the command</p>
<p><strong>____________ALT Key Bound___________</strong><br />
Alt + &lt; &#8211; Move to the first line in the history<br />
Alt + &gt; &#8211; Move to the last line in the history<br />
Alt + ? &#8211; Show current completion list<br />
Alt + * &#8211; Insert all possible completions<br />
Alt + / &#8211; Attempt to complete filename<br />
Alt + . &#8211; Yank last argument to previous command<br />
Alt + b &#8211; Move backward<br />
Alt + c &#8211; Capitalize the word<br />
Alt + d &#8211; Delete word<br />
Alt + f &#8211; Move forward<br />
Alt + l &#8211; Make word lowercase<br />
Alt + n &#8211; Search the history forwards non-incremental<br />
Alt + p &#8211; Search the history backwards non-incremental<br />
Alt + r &#8211; Recall command<br />
Alt + t &#8211; Move words around<br />
Alt + u &#8211; Make word uppercase<br />
Alt + back-space &#8211; Delete backward from cursor<br />
<strong><br />
&#8212;&#8212;&#8212;&#8212;&#8212;- More Special Keybindings &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</strong></p>
<p>Here &#8220;2T&#8221; means Press TAB twice</p>
<p>$ 2T &#8211; All available commands(common)<br />
$ (string)2T &#8211; All available commands starting with (string)<br />
$ /2T &#8211; Entire directory structure including Hidden one<br />
$ 2T &#8211; Only Sub Dirs inside including Hidden one<br />
$ *2T &#8211; Only Sub Dirs inside without Hidden one<br />
$ ~2T &#8211; All Present Users on system from &#8220;/etc/passwd&#8221;<br />
$ $2T &#8211; All Sys variables<br />
$ @2T &#8211; Entries from &#8220;/etc/hosts&#8221;<br />
$ =2T &#8211; Output like ls or dir</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/sysadmin-tips-bash-shell-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find dead softlink files by shell</title>
		<link>http://www.admon.org/find-dead-softlink-files-by-shell/</link>
		<comments>http://www.admon.org/find-dead-softlink-files-by-shell/#comments</comments>
		<pubDate>Thu, 10 May 2007 10:30:43 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[softlink]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=329</guid>
		<description><![CDATA[Symbolic linked files are commonly used in Linux system. For example some service inital scripts are stored in /etc/init.d and linked to /etc/rc0.d, /etc/rc1.d, /etc/rc2.d, /etc/rc3.d, /etc/rc4.d, /etc/rc5.d and /etc/rc6.d, so that the system is able to control related services in different runlevel. But sometimes if the symlink files got broken, how can we find [...]]]></description>
			<content:encoded><![CDATA[<p>Symbolic linked files are commonly used in Linux system. For example some service inital scripts are stored in /etc/init.d and linked to /etc/rc0.d, /etc/rc1.d, /etc/rc2.d, /etc/rc3.d, /etc/rc4.d, /etc/rc5.d and /etc/rc6.d, so that the system is able to control related services in different runlevel.<span id="more-329"></span></p>
<p>But sometimes if the <a href="http://en.wikipedia.org/wiki/Symbolic_link">symlink files</a> got broken, how can we find the dead ones out?</p>
<p>Here&#8217;s a simple script does the work well:</p>
<p>[planet@admon ~]$ cat check-dead-softlink.sh</p>
<pre>[planet@admon ~]$ cat check-dead-softlink.sh
#!/bin/bash
#
# joseph from http://planet.admon.org
# This script is intended to find broken symlinks for
# a list of specified directories.

[ $# -eq 0 ] &amp;&amp; directorys=`pwd` || directorys=$@

linkchk()
{
        for file in $1/*
        do
        [ -L "$file" -a ! -e "$file" ] &amp;&amp; echo "$file"
        [ -d "$file" ]&amp;&amp;linkchk $file
        done
}

for directory in $directorys
do
    [ -d $directory ] &amp;&amp; linkchk $directory
  else
    echo "$directory is not a directory, request ignored!"
    echo "Usage: $0 dir1 dir2 dir3 ..."
  fi
done
exit 0</pre>
<p>The output from an examining case:</p>
<pre>[planet@admon ~]$ cd shell/
[planet@admon shell]$ ls -l symbol
lrwxrwxrwx 1 root root 28 Oct 10 15:19 symbol -&gt; /home/oracle/hldataadmin.dmp
[planet@admon shell]$ cat symbol
cat: symbol: No such file or directory
[planet@admon shell]$ cd ..
[planet@admon ~]$ ./check-dead-softlink.sh shell
"shell/symbol"</pre>
<p>If you face any issues on this script, please dont hesitate to create a post here at <a href="http://forum.admon.org/linux-scripting/">Linux Scripting</a> at <a href="http://forum.admon.org/">Forum.Admon.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/find-dead-softlink-files-by-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

