<?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>LosByers- Interesting Musings Helpful Hints from a Unix System Administrator &#187; KSH</title>
	<atom:link href="http://losbyers.com/wordpress/tag/ksh/feed/" rel="self" type="application/rss+xml" />
	<link>http://losbyers.com/wordpress</link>
	<description>All the info I need</description>
	<lastBuildDate>Fri, 30 Mar 2012 15:56:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Helpful Unix commands</title>
		<link>http://losbyers.com/wordpress/2009/12/helpful-unix-commands/</link>
		<comments>http://losbyers.com/wordpress/2009/12/helpful-unix-commands/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 17:32:10 +0000</pubDate>
		<dc:creator>LosByers</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[KSH]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://losbyers.com/wordpress/?p=68</guid>
		<description><![CDATA[<p>A thread dedicated to those useful Unix commands we all know and love.  Ya right. </p> <p>I need a really tricky find command the other day so I came up with the following.  I wanted to save the command some where as it really shows the power of find</p> <p>Find all files that are not [...]]]></description>
			<content:encoded><![CDATA[<p><span>A thread dedicated to those useful Unix commands we all know and love.  Ya right. <img title="Shocked" src="http://www.losbyers.com/modules/Forums/images/smiles/icon_eek.gif" border="0" alt="Shocked" /></p>
<p>I need a really tricky <span style="font-style: italic;">find</span> command the other day so I came up with the following.  I wanted to save the command some where as it really shows the power of <span style="font-style: italic;">find</span></p>
<p>Find all files that are not in the images or languages directory that are older than seven days that end with .php or .doc and delete them also leave a log file of what was deleted.</p>
<p><span style="font-weight: bold;"> find ./  \( -name images -o -name languages \) -prune -o \( -name &#8216;*.php&#8217; -o -name &#8216;*.doc&#8217; \) -mtime +7 -exec rm {} \; -print &gt; /var/tmp/deleted_files</span></p>
<p>Sorry the command is all on one line.  Because the <span style="font-style: italic;">find</span> statement is utilizing regular expressions and complex statements, ie &#8220;<span style="font-weight: bold;">\(</span>&#8220;, so you can&#8217;t use the &#8220;\&#8221; and take the statement to the next line.</p>
<p>To read the command better take it one step at a time.<br />
Find all files or directories that have the name &#8220;images&#8221; OR the name &#8220;languages&#8221; and prune/remove those items found from the find results.   Using the -prune option is a great way to setup exclusions.  The next &#8220;-o&#8221; OR says if the files found are not named &#8220;images&#8221; or &#8220;languages&#8221; find the files that end in &#8220;.php&#8221; or &#8220;.doc&#8221; that are older than 7 days.  If anything is found that meets the conditions then remove those files and &#8220;print&#8221; the file name out to the log file.</span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Flosbyers.com%2Fwordpress%2F2009%2F12%2Fhelpful-unix-commands%2F&amp;title=Helpful%20Unix%20commands" id="wpa2a_2"><img src="http://losbyers.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://losbyers.com/wordpress/2009/12/helpful-unix-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pass a Shell variable to a SED command</title>
		<link>http://losbyers.com/wordpress/2009/12/pass-a-shell-variable-to-a-sed-command/</link>
		<comments>http://losbyers.com/wordpress/2009/12/pass-a-shell-variable-to-a-sed-command/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 17:29:40 +0000</pubDate>
		<dc:creator>LosByers</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[KSH]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://losbyers.com/wordpress/?p=65</guid>
		<description><![CDATA[<p>I just helped a friend out with placing a shell variable into a sed command and thought it would be prudent to document it.</p> <p>This set of commands was to be used to change directory names inside a samba share, hense the directory names of \ and the unix escape needed making a bunch of [...]]]></description>
			<content:encoded><![CDATA[<p><span>I just helped a friend out with placing a shell variable into a sed command and thought it would be prudent to document it.</p>
<p>This set of commands was to be used to change directory names inside a samba share, hense the directory names of \ and the unix escape needed making a bunch of \\ appear.</p>
<p>server_name#  <strong>DIR=&#8221;blahblah&#8221; </strong><br />
server_name#  <strong>echo &#8220;bob&#8221; | sed &#8220;s/^/${DIR}\\\ADMIND__${DIR}\\\/&#8221; </strong><br />
<span style="font-weight: bold;">blahblah\ADMIND__blahblah\bob</span><br />
</span></p>
<p><span><br />
Set the variable DIR to &#8220;blahblah&#8221;, I should have just used &#8220;foo&#8221; it&#8217;s less to type.  Now echo the word &#8220;bob&#8221; but first add our variable and a prefix of &#8220;ADMIND__&#8221; to the front of bob.<br />
</span></p>
<p><span>I wanted to show another example, but don&#8217;t have time at the momment.</p>
<p>The important things to remember is to have the variables enclosed in double quotes.</span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Flosbyers.com%2Fwordpress%2F2009%2F12%2Fpass-a-shell-variable-to-a-sed-command%2F&amp;title=Pass%20a%20Shell%20variable%20to%20a%20SED%20command" id="wpa2a_4"><img src="http://losbyers.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://losbyers.com/wordpress/2009/12/pass-a-shell-variable-to-a-sed-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unix Terminal Headers and Titles</title>
		<link>http://losbyers.com/wordpress/2009/12/unix-terminal-headers-and-titles/</link>
		<comments>http://losbyers.com/wordpress/2009/12/unix-terminal-headers-and-titles/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:08:31 +0000</pubDate>
		<dc:creator>LosByers</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[KSH]]></category>

		<guid isPermaLink="false">http://losbyers.com/wordpress/?p=44</guid>
		<description><![CDATA[<p>Please see another post of mine about terminal colors if this post is a little confusing.</p> <p>Add the following to your .kshrc or .bashrc files.</p> <p># KSH terminal headers add to .profile PS1=`uname -n`&#8221; $ &#8221; alias cd=_cd function _cd { \cd ${1+&#8221;$@&#8221;} &#38;&#38; echo &#8220;\033]0;${USER}@${HOST}: ${PWD}\007\c&#8221; }</p> <p># BASH terminal headers add to .bashrc [...]]]></description>
			<content:encoded><![CDATA[<p>Please see another post of mine about <a title="terminal font colors" href="http://losbyers.com/wordpress/2009/12/unix-terminal-font-colors/" target="_blank">terminal colors</a> if this post is a little confusing.</p>
<p>Add the following to your .kshrc or .bashrc files.</p>
<p><span># KSH terminal headers add to .profile<br />
PS1=`uname -n`&#8221; $ &#8221;<br />
alias cd=_cd<br />
function _cd {<br />
\cd ${1+&#8221;$@&#8221;} &amp;&amp; echo &#8220;\033]0;${USER}@${HOST}: ${PWD}\007\c&#8221;<br />
}</span></p>
<p># BASH terminal headers add to .bashrc<br />
PROMPT_COMMAND=&#8217;echo -ne &#8220;\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007&#8243;&#8216;<br />
# PS1=&#8217;\h] \w\$ &#8216; #simple prompt with hostname and current path<br />
PS1=&#8217;\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]&#8216; #color prompt</p>
<p><span><span id="more-44"></span>More detailed historic type information.</span></p>
<p><span>So you want the title bar to look different in you xterm or terminal window?</span></p>
<p>This also works for Putty terminal windows.</p>
<p><span style="font-weight: bold;">echo -n ^[]1\;$icon_name\^G^[]2\;$HOSTNAME\: $cwd\^G&#8217;</span></p>
<p>Two small changes will be necessary after this text is cut &amp; pasted.<br />
Replace the &#8220;^[" and "^G" characters with esc and CNTL-G by typing [ctrl-v][esc] and [ctrl-v][ctrl-g].</p>
<p>You can set up an alias</p>
<p><span style="font-weight: bold;">alias mytitle &#8216;icon_name; echo -n ^[]1\;$icon_name\^G^[]2\;$HOSTNAME\: $cwd\^G&#8217; </span></p>
<p>Then set an alias to change your prompt and title</p>
<p><span style="font-weight: bold;">alias cd &#8216;chdir \!*;set prompt=&#8221;`dirs`#\\!% &#8220;; mytitle&#8217;</span></p>
<p>Another way of stating this is:<br />
Window and icon titles may be changed in a running xterm by using XTerm escape sequences. The following sequences are useful in this respect:</p>
<p>ESC]0;stringBEL &#8212; Set icon name and window title to string<br />
ESC]1;stringBEL &#8212; Set icon name to string<br />
ESC]2;stringBEL &#8212; Set window title to string<br />
where ESC is the escape character (\033), and BEL is the bell character (\007).</p>
<p><span style="font-weight: bold;"> echo -n &#8220;\033]0;${USER}@${HOST}\007&#8243; </span></p>
<p>should produce a title like username@hostname, assuming the shell variables $USER and $HOST are set correctly.</p>
<p><span>&#8212;-</span></p>
<p><span>I found the following also works very well.</span></p>
<p>Add these lines to your .profile for KSH or .bashrc for BASH and just uncomment the KSH or BASH line.</p>
<p><span style="color: green;">function _cd {<br />
# KSH terminal headers<br />
# \cd ${1+&#8221;$@&#8221;} &amp;&amp; echo &#8220;\033]0;${USER}@${HOST}: ${PWD}\007\c&#8221;<br />
# BASH terminal headers<br />
# \cd ${1+&#8221;$@&#8221;} &amp;&amp; echo -ne &#8220;\033]0;${USER}@${HOST}: ${PWD}\007&#8243;<br />
}</span></p>
<p>alias cd=_cd</p>
<p># Cool Colored prompt for BASH Shells it shows user@host and Present directory, but not the whole PATH.<br />
# PS1=&#8217;\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]&#8216;</p>
<p>I also like to add the following to my .bashrc so that I can use VI type commands<br />
set -o vi</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Flosbyers.com%2Fwordpress%2F2009%2F12%2Funix-terminal-headers-and-titles%2F&amp;title=Unix%20Terminal%20Headers%20and%20Titles" id="wpa2a_6"><img src="http://losbyers.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://losbyers.com/wordpress/2009/12/unix-terminal-headers-and-titles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Too many processes script</title>
		<link>http://losbyers.com/wordpress/2009/12/too-many-processes-script/</link>
		<comments>http://losbyers.com/wordpress/2009/12/too-many-processes-script/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:05:22 +0000</pubDate>
		<dc:creator>LosByers</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[KSH]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://losbyers.com/wordpress/?p=42</guid>
		<description><![CDATA[<p>KSH script to check the number of processes on a system and send an email if there are too many.</p> <p>I liked this as it was simple, but had some nice elements that could be used elsewhere.</p> <p>#!/bin/ksh # # Script to check for run away ftp processes. # 04/08 &#8211; Mike Byers</p> <p>HOST=`uname -n` [...]]]></description>
			<content:encoded><![CDATA[<p>KSH script to check the number of processes on a system and send an email if there are too many.</p>
<p>I liked this as it was simple, but had some nice elements that could be used elsewhere.</p>
<p><span style="color: #800080;">#!/bin/ksh<br />
#<br />
# Script to check for run away ftp processes.<br />
# 04/08 &#8211; Mike Byers</p>
<p>HOST=`uname -n`<br />
ADMINZ=&#8221;admin@somewhere.com&#8221;<br />
# Add email Recipients<br />
RECPTS=&#8221;email_add@somewhere.com&#8221;</p>
<p># Let the user pass an argument or default to ftp<br />
if [ $1 ];<br />
then<br />
APP=&#8221;$1&#8243;<br />
else<br />
APP=&#8221;ftp&#8221;<br />
fi</p>
<p>num=`ps -ea -o &#8216;user pid time pmem comm&#8217; | grep $APP | wc -l`</p>
<p>if  [ $num -gt 6 ];<br />
then<br />
# Do stuff if there are too many active processes.</p>
<p># echo &#8220;Number of processes is too many at $num &#8221;<br />
# Kill all active ftp processes<br />
# pkill -9 -n $APP</p>
<p># Send notification only<br />
echo &#8220;Number of $APP processes is too many at $num on $HOST for user $LOGNAME&#8221; | /bin/mailx -r $ADMINZ -s &#8220;Too many processes on $HOST for user $LOGNAME&#8221; $ADMINZ $RECPTS</p>
<p>fi</span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Flosbyers.com%2Fwordpress%2F2009%2F12%2Ftoo-many-processes-script%2F&amp;title=Too%20many%20processes%20script" id="wpa2a_8"><img src="http://losbyers.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://losbyers.com/wordpress/2009/12/too-many-processes-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command Line Search and Replace</title>
		<link>http://losbyers.com/wordpress/2009/12/command-line-search-and-replace/</link>
		<comments>http://losbyers.com/wordpress/2009/12/command-line-search-and-replace/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:02:17 +0000</pubDate>
		<dc:creator>LosByers</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[Web Related]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[KSH]]></category>

		<guid isPermaLink="false">http://losbyers.com/wordpress/?p=39</guid>
		<description><![CDATA[<p>So you want to change some text in many unix files.</p> <p>Try the following.</p> <p>perl -pi -e &#8216;s/find/replace/g&#8217; *.txt</p> <p>or to script it out. Find the TEXT in regular files and replace with NEWTEXT</p> <p>for file in `find ./ -type f -exec grep -l TEXT {} \;` do perl -pi -e &#8216;s/TEXT/NEWTEXT/g&#8217; $file done </p> [...]]]></description>
			<content:encoded><![CDATA[<p><span>So you want to change some text in many unix files.</p>
<p>Try the following.</p>
<p>perl -pi -e &#8216;s/find/replace/g&#8217; *.txt</p>
<p>or to script it out.<br />
Find the TEXT in regular files and replace with NEWTEXT</p>
<p>for file in `find ./ -type f -exec grep -l TEXT {} \;`<br />
do<br />
<strong>perl -pi -e &#8216;s/TEXT/NEWTEXT/g&#8217; $file </strong><br />
done </span></p>
<p><span><span id="more-39"></span></span><span>I found out how to pass KSH variables to awk, just in case this ever comes in handy.</p>
<p><span style="font-weight: bold;">VAR=&#8221;some_data&#8221;</p>
<p>echo &#8220;This is nice&#8221; | awk &#8216;{ print $1, avar, $2, $3 }&#8217; avar=$VAR</span></p>
<p>&gt; This some_data is nice</p>
<p>Or a better example; Changing file names.</p>
<p><span style="font-weight: bold;">VAR=&#8221;.poop&#8221;<br />
for x in *.php<br />
do<br />
echo &#8220;moving $x to \c&#8221; ;echo $x | awk -F. &#8216;{ print $1 newext }&#8217; newext=$VAR<br />
mv $x `echo $x | awk -F. &#8216;{ print $1 newext }&#8217; newext=$VAR&#8217;`<br />
done</span></p>
<p>&gt; moving test1.php to test1.poop<br />
&gt; moving test2.php to test2.poop<br />
&gt; moving test3.php to test3.poop</p>
<p>Of course if you had a file called test.this.file.php the awk statement above would mv it to test.poop and drop the other items after the first period.  There is probably a nice way to code around this, but hey, this works. for now.</span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Flosbyers.com%2Fwordpress%2F2009%2F12%2Fcommand-line-search-and-replace%2F&amp;title=Command%20Line%20Search%20and%20Replace" id="wpa2a_10"><img src="http://losbyers.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://losbyers.com/wordpress/2009/12/command-line-search-and-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

