<?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>dan.thoughts &#187; Shell Scripting</title>
	<atom:link href="http://blog.sosedoff.com/category/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sosedoff.com</link>
	<description>Web-development, PHP, Ruby, Sinatra, Merb, Rails, MySQL, SQLite, Web Services.</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:54:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fast and easy password generation</title>
		<link>http://blog.sosedoff.com/2011/01/22/fast-and-easy-password-generation/</link>
		<comments>http://blog.sosedoff.com/2011/01/22/fast-and-easy-password-generation/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 01:21:15 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=316</guid>
		<description><![CDATA[I used to generate a lot of passwords and usually it would be an online service found by googling &#8220;generate password online&#8221;. It worked fine until i got tired of it and decided to find something else, much easier and faster. Something that will give me the results right away from terminal while doing server [...]]]></description>
			<content:encoded><![CDATA[<p>I used to generate a lot of passwords and usually it would be an online service found by googling &#8220;generate password online&#8221;. It worked fine until i got tired of it and decided to find something else, much easier and faster. Something that will give me the results right away from terminal while doing server setup. </p>
<p>Here we go, bash script (found online and modified by my needs):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">charspool</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'a'</span> <span style="color: #ff0000;">'b'</span> <span style="color: #ff0000;">'c'</span> <span style="color: #ff0000;">'d'</span> <span style="color: #ff0000;">'e'</span> <span style="color: #ff0000;">'f'</span> <span style="color: #ff0000;">'g'</span> <span style="color: #ff0000;">'h'</span> <span style="color: #ff0000;">'i'</span> <span style="color: #ff0000;">'j'</span> <span style="color: #ff0000;">'k'</span> <span style="color: #ff0000;">'l'</span> <span style="color: #ff0000;">'m'</span> <span style="color: #ff0000;">'n'</span> <span style="color: #ff0000;">'o'</span> <span style="color: #ff0000;">'p'</span>
<span style="color: #ff0000;">'q'</span> <span style="color: #ff0000;">'r'</span> <span style="color: #ff0000;">'s'</span> <span style="color: #ff0000;">'t'</span> <span style="color: #ff0000;">'u'</span> <span style="color: #ff0000;">'v'</span> <span style="color: #ff0000;">'w'</span> <span style="color: #ff0000;">'x'</span> <span style="color: #ff0000;">'y'</span> <span style="color: #ff0000;">'z'</span> <span style="color: #ff0000;">'0'</span> <span style="color: #ff0000;">'1'</span> <span style="color: #ff0000;">'2'</span> <span style="color: #ff0000;">'3'</span> <span style="color: #ff0000;">'4'</span> <span style="color: #ff0000;">'5'</span> <span style="color: #ff0000;">'6'</span> <span style="color: #ff0000;">'7'</span>
<span style="color: #ff0000;">'8'</span> <span style="color: #ff0000;">'9'</span> <span style="color: #ff0000;">'0'</span> <span style="color: #ff0000;">'A'</span> <span style="color: #ff0000;">'B'</span> <span style="color: #ff0000;">'C'</span> <span style="color: #ff0000;">'D'</span> <span style="color: #ff0000;">'E'</span> <span style="color: #ff0000;">'F'</span> <span style="color: #ff0000;">'G'</span> <span style="color: #ff0000;">'H'</span> <span style="color: #ff0000;">'I'</span> <span style="color: #ff0000;">'J'</span> <span style="color: #ff0000;">'K'</span> <span style="color: #ff0000;">'L'</span> <span style="color: #ff0000;">'M'</span> <span style="color: #ff0000;">'N'</span> <span style="color: #ff0000;">'O'</span>
<span style="color: #ff0000;">'P'</span> <span style="color: #ff0000;">'Q'</span> <span style="color: #ff0000;">'R'</span> <span style="color: #ff0000;">'S'</span> <span style="color: #ff0000;">'T'</span> <span style="color: #ff0000;">'U'</span> <span style="color: #ff0000;">'V'</span> <span style="color: #ff0000;">'W'</span> <span style="color: #ff0000;">'X'</span> <span style="color: #ff0000;">'Y'</span> <span style="color: #ff0000;">'Z'</span> <span style="color: #ff0000;">'-'</span> <span style="color: #ff0000;">'_'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
&nbsp;
<span style="color: #007800;">len</span>=<span style="color: #800000;">${#charspool[*]}</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #007800;">num</span>=<span style="color: #000000;">20</span>;
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #007800;">num</span>=$<span style="color: #000000;">1</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">randomnumbers</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-c</span> <span style="color: #007800;">$num</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">od</span> <span style="color: #660033;">-t</span> u1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{for (i = 2; i &lt;= NF; i++) print $i}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;password: &quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> c <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$randomnumbers</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #800000;">${charspool[$((c % len))]}</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span></pre></div></div>

<h3>Installation</h3>
<p>Just create a script called something like &#8220;genpassword&#8221; in your bin dir and make it executable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>genpassword
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>genpassword</pre></div></div>

<p>Works on any unix-like machine with bash installed.</p>
<h3>Usage</h3>
<p>Usage is pretty straight-forward. Just type &#8220;genpassword&#8221; in terminal and you&#8217;ll get the password.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">genpassword <span style="color: #666666; font-style: italic;"># This will give a default length (20 chars) password</span>
genpassword <span style="color: #000000;">64</span> <span style="color: #666666; font-style: italic;"># This will give you a 64 chars long password</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2011/01/22/fast-and-easy-password-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet: Cleanup your Git repository</title>
		<link>http://blog.sosedoff.com/2010/06/15/snippet-cleanup-your-git-repository/</link>
		<comments>http://blog.sosedoff.com/2010/06/15/snippet-cleanup-your-git-repository/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 06:35:56 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cleanup]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=240</guid>
		<description><![CDATA[Snippet (found on net) for removing files from repository that are no longer present under your project.

$ git rm $&#40;git ls-files -d&#41;

For best use add it to bash alias file: ~/.bashrc or ~/.bash-aliases (under ubuntu):

alias gitclean='git rm $(git ls-files -d)'

]]></description>
			<content:encoded><![CDATA[<p>Snippet (found on net) for removing files from repository that are no longer present under your project.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git <span style="color: #c20cb9; font-weight: bold;">rm</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>git ls-files -d<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>For best use add it to bash alias file: ~/.bashrc or ~/.bash-aliases (under ubuntu):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gitclean</span>=<span style="color: #ff0000;">'git rm $(git ls-files -d)'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/15/snippet-cleanup-your-git-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting processor affinity for a certain task or process in Linux</title>
		<link>http://blog.sosedoff.com/2010/06/06/setting-processor-affinity-for-a-certain-task-or-process-in-linux/</link>
		<comments>http://blog.sosedoff.com/2010/06/06/setting-processor-affinity-for-a-certain-task-or-process-in-linux/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 01:43:37 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[cores]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[smp]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=218</guid>
		<description><![CDATA[When you are using SMP you might want to override the kernel&#8217;s process scheduling and bind a certain process to a specific CPU(s).
What is this?
CPU affinity is nothing but a scheduler property that &#8220;bonds&#8221; a process to a given set of CPUs on the SMP system. The Linux scheduler will honor the given CPU affinity [...]]]></description>
			<content:encoded><![CDATA[<p>When you are using <a href="http://en.wikipedia.org/wiki/Symmetric_multiprocessing">SMP</a> you might want to override the kernel&#8217;s process scheduling and bind a certain process to a specific CPU(s).</p>
<h4>What is this?</h4>
<p>CPU affinity is nothing but a scheduler property that &#8220;bonds&#8221; a process to a given set of CPUs on the SMP system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity:</p>
<blockquote><p>The scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications. For example, application such as Oracle (ERP apps) use # of cpus per instance licensed. You can bound Oracle to specific CPU to avoid license problem. This is a really useful on large server having 4 or 8 CPUS</p></blockquote>
<h4>Setting processor affinity for a certain task or process using taskset command</h4>
<p>taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. However taskset is not installed by default. You need to install schedutils (Linux scheduler utilities) package.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> shedutils</pre></div></div>

<p>Under latest version of Debian / Ubuntu Linux taskset is installed by default using util-linux package.</p>
<p>The CPU affinity is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. For example:</p>
<ul>
<li>0&#215;00000001 is processor #0 (1st processor)</li>
<li>0&#215;00000003 is processors #0 and #1</li>
<li>0&#215;00000004 is processors #2 (3rd processor)</li>
</ul>
<p>To set the processor affinity of process 13545 to processor #0 (1st processor) type following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ taskset 0x00000001 <span style="color: #660033;">-p</span> <span style="color: #000000;">13545</span></pre></div></div>

<p>If you find a bitmask hard to use, then you can specify a numerical list of processors instead of a bitmask using -c flag:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ taskset <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">13545</span>
$ taskset <span style="color: #660033;">-c</span> <span style="color: #000000;">3</span>,<span style="color: #000000;">4</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">13545</span></pre></div></div>

<p>where  -p : Operate on an existing PID and not launch a new task (default is to launch a new task)</p>
<p><small>via <a href="http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html">http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/06/setting-processor-affinity-for-a-certain-task-or-process-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date separated MySQL backups</title>
		<link>http://blog.sosedoff.com/2009/09/18/date-separated-mysql-backups/</link>
		<comments>http://blog.sosedoff.com/2009/09/18/date-separated-mysql-backups/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 14:04:59 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=163</guid>
		<description><![CDATA[Here is the bash shell script that makes archived dumps of your database server. All databases are separated from each other and stored into date based folders. 

#!/bin/bash

MyUSER="root"
MyPASS=""
MyHOST="localhost"
NOW="$(date +"%d-%m-%Y")"
STOREDIR="/home/storage/backup/database/by_dates/$NOW"
DBLIST="$(mysql -u $MyUSER -h $MyHOST -Bse 'show databases')"

[ ! -d $STOREDIR ] &#038;&#038; mkdir -p $STOREDIR &#124;&#124; :

for db in $DBLIST
do
	FILE="$STOREDIR/$db.gz"
	mysqldump -u $MyUSER -h $MyHOST $db &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the bash shell script that makes archived dumps of your database server. All databases are separated from each other and stored into date based folders. </p>
<pre>
#!/bin/bash

MyUSER="root"
MyPASS=""
MyHOST="localhost"
NOW="$(date +"%d-%m-%Y")"
STOREDIR="/home/storage/backup/database/by_dates/$NOW"
DBLIST="$(mysql -u $MyUSER -h $MyHOST -Bse 'show databases')"

[ ! -d $STOREDIR ] &#038;&#038; mkdir -p $STOREDIR || :

for db in $DBLIST
do
	FILE="$STOREDIR/$db.gz"
	mysqldump -u $MyUSER -h $MyHOST $db | gzip -9 > $FILE
done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/09/18/date-separated-mysql-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Init.d nginx script for Debian and RHEL systems</title>
		<link>http://blog.sosedoff.com/2009/03/15/initd-nginx-script-for-debian-and-rhel-systems/</link>
		<comments>http://blog.sosedoff.com/2009/03/15/initd-nginx-script-for-debian-and-rhel-systems/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:14:19 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[init script]]></category>
		<category><![CDATA[init.d]]></category>
		<category><![CDATA[rhel]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=108</guid>
		<description><![CDATA[Here is general init.d nginx script that working on Debian and RHEL/CentOS systems. It`s set to default configuration with main path to nginx = /usr/local/nginx

#!/bin/sh
#
# Init file for nginx
#
# chkconfig: 2345 55 25
# description: Nginx web server
#
# processname: nginx
# config: /usr/local/nginx/nginx.conf
# pidfile: /usr/local/nginx/nginx.pid
&#160;
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# [...]]]></description>
			<content:encoded><![CDATA[<p>Here is general init.d nginx script that working on Debian and RHEL/CentOS systems. It`s set to default configuration with main path to nginx = /usr/local/nginx</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Init file for nginx</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># chkconfig: 2345 55 25</span>
<span style="color: #666666; font-style: italic;"># description: Nginx web server</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># processname: nginx</span>
<span style="color: #666666; font-style: italic;"># config: /usr/local/nginx/nginx.conf</span>
<span style="color: #666666; font-style: italic;"># pidfile: /usr/local/nginx/nginx.pid</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and</span>
<span style="color: #666666; font-style: italic;"># run 'sudo update-rc.d nginx defaults', or use the appropriate command on your</span>
<span style="color: #666666; font-style: italic;"># distro. For CentOS/Redhat run: '/sbin/chkconfig --add nginx'</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Author: Ryan Norbauer &lt;ryan.norbauer@gmail.com&gt;</span>
<span style="color: #666666; font-style: italic;"># Modified: Geoffrey Grosenbach http://topfunky.com</span>
<span style="color: #666666; font-style: italic;"># Modified: David Krmpotic http://davidhq.com</span>
<span style="color: #666666; font-style: italic;"># Modified: Vishnu Gopal http://vish.in</span>
<span style="color: #666666; font-style: italic;"># Modified: Dan Sosedov &lt;dan.sosedoff@gmail.com&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">DESC</span>=<span style="color: #ff0000;">&quot;nginx daemon&quot;</span>
<span style="color: #007800;">NAME</span>=nginx
<span style="color: #007800;">DAEMON</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
<span style="color: #007800;">CONFIGFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>nginx.conf
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid
<span style="color: #007800;">SCRIPTNAME</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Gracefully exit if the package has been removed.</span>
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
d_start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">-c</span> <span style="color: #007800;">$CONFIGFILE</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> already running&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
d_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-QUIT</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> not running&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
d_reload<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$PIDFILE</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> can't reload&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
    d_start
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
    d_stop
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading <span style="color: #007800;">$DESC</span> configuration...&quot;</span>
    d_reload
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting <span style="color: #007800;">$DESC</span>: <span style="color: #007800;">$NAME</span>&quot;</span>
    d_stop
    <span style="color: #666666; font-style: italic;"># One second might not be time enough for a daemon to stop,</span>
    <span style="color: #666666; font-style: italic;"># if this happens, d_start will fail (and dpkg will break if</span>
    <span style="color: #666666; font-style: italic;"># the package is being upgraded). Change the timeout if needed</span>
    <span style="color: #666666; font-style: italic;"># be, or change d_stop to have start-stop-daemon use --retry.</span>
    <span style="color: #666666; font-style: italic;"># Notice that using --retry slows down the shutdown process somewhat.</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
    d_start
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: <span style="color: #007800;">$SCRIPTNAME</span> {start|stop|restart|reload}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">3</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #7a0874; font-weight: bold;">&#40;</span>start<span style="color: #000000; font-weight: bold;">|</span>stop<span style="color: #000000; font-weight: bold;">|</span>restart<span style="color: #000000; font-weight: bold;">|</span>reload<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>You also can download it &#8211; <a href="http://files.sosedoff.com/e570e29f/">http://files.sosedoff.com/e570e29f/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/03/15/initd-nginx-script-for-debian-and-rhel-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting to wifi with specified wep key index</title>
		<link>http://blog.sosedoff.com/2009/03/09/connecting-to-wifi-with-specified-wep-key-index/</link>
		<comments>http://blog.sosedoff.com/2009/03/09/connecting-to-wifi-with-specified-wep-key-index/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 03:41:12 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[WiFi]]></category>
		<category><![CDATA[key index]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[wep]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=75</guid>
		<description><![CDATA[Since i got trouble while connecting to wireless network with given parameters in linux, i tried a lot of ways to get my internet working. 
So, the problem is: Windows Network manager have special option &#8211; Key index. The index is transmitted with the encrypted message. The receiver then looks-up the key corresponding to the [...]]]></description>
			<content:encoded><![CDATA[<p>Since i got trouble while connecting to wireless network with given parameters in linux, i tried a lot of ways to get my internet working. </p>
<p>So, the problem is: Windows Network manager have special option &#8211; Key index. The index is transmitted with the encrypted message. The receiver then looks-up the key corresponding to the transmitted index and uses it to decrypt the message. But linux (ubuntu) network managers i`ve tried have no key index field, so there is no way to set it up properly with gui. Connection won`t work if index value set to incorrect value. </p>
<p>After giving up to find any useful gui program i wrote small shell script only for one network (because i have no access to router and no chance to improve some security settings):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># settings</span>
<span style="color: #007800;">interface</span>=<span style="color: #ff0000;">&quot;ath0&quot;</span> <span style="color: #666666; font-style: italic;"># wireless interface, default to wlan0</span>
<span style="color: #007800;">essid</span>=<span style="color: #ff0000;">&quot;NETWORK_NAME_HERE&quot;</span>
<span style="color: #007800;">key</span>=<span style="color: #ff0000;">&quot;YOUR_KEY_HERE&quot;</span>
<span style="color: #007800;">index</span>=<span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #666666; font-style: italic;"># can be [1..4]</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check permission</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Run this script under root&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># show information</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Settings:&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-&gt; Interface: <span style="color: #007800;">$interface</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-&gt; Wifi ESSID: <span style="color: #007800;">$essid</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-&gt; Key: <span style="color: #007800;">$key</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-&gt; Key Index: <span style="color: #007800;">$index</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># perform association</span>
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$interface</span> down
iwconfig <span style="color: #007800;">$interface</span> essid <span style="color: #007800;">$essid</span>
iwconfig <span style="color: #007800;">$interface</span> key <span style="color: #007800;">$key</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">$index</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
iwconfig <span style="color: #007800;">$interface</span> key <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">$index</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$interface</span> up
dhclient <span style="color: #007800;">$interface</span></pre></div></div>

<p>Download shell script &#8211; <a href="http://files.sosedoff.com/9591756c/">http://files.sosedoff.com/9591756c/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/03/09/connecting-to-wifi-with-specified-wep-key-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check root user permissions in bash scripts</title>
		<link>http://blog.sosedoff.com/2009/03/09/check-root-user-permissions-in-bash-scripts/</link>
		<comments>http://blog.sosedoff.com/2009/03/09/check-root-user-permissions-in-bash-scripts/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 03:07:33 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=71</guid>
		<description><![CDATA[For example, in your bash shell script you`re going to use some root-specific commands like network operations, mounting devices and so on. There are couple easy ways to check if your script is executing under root privileges.

#!/bin/bash
# ...
if &#91; &#34;$(id -u)&#34; != &#34;0&#34; &#93;; then
   echo &#34;This script must be run as root&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>For example, in your bash shell script you`re going to use some root-specific commands like network operations, mounting devices and so on. There are couple easy ways to check if your script is executing under root privileges.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># ...</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This script must be run as root&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;"># ...</span></pre></div></div>

<p>Another way: use EUID. When user account created a user ID is assigned to each user. Bash shell stores the user ID in $UID variable. Your effective user ID is stored in $EUID variable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># ...</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$EUID</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This script must be run as root&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;"># ...</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/03/09/check-root-user-permissions-in-bash-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN auto add and delete</title>
		<link>http://blog.sosedoff.com/2009/01/16/svn-auto-add-and-delete/</link>
		<comments>http://blog.sosedoff.com/2009/01/16/svn-auto-add-and-delete/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 13:55:44 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[auto delete and add]]></category>
		<category><![CDATA[autocommit]]></category>
		<category><![CDATA[commit]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=32</guid>
		<description><![CDATA[Bored of manually delete and add files to project? Ok, me too   So, i decided to make a simple command to work with command &#8220;svn commit&#8221;. All-in-one solution is:

#!/bin/bash
&#160;
echo &#34;processing files to add...&#34;
svn status &#124; grep “^?” &#124; sed -r ’s/^\?&#91; &#93;+//’ &#124; xargs -r svn add
&#160;
echo &#34;processing files to delete...&#34;
svn status &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>Bored of manually delete and add files to project? Ok, me too <img src='http://blog.sosedoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So, i decided to make a simple command to work with command &#8220;svn commit&#8221;. All-in-one solution is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;processing files to add...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> status <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> “^?” <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-r</span> ’s<span style="color: #000000; font-weight: bold;">/</span>^\?<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #000000; font-weight: bold;">//</span>’ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-r</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> add
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;processing files to delete...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> status <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> “^<span style="color: #000000; font-weight: bold;">!</span>” <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-r</span> ’s<span style="color: #000000; font-weight: bold;">/</span>^\<span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #000000; font-weight: bold;">//</span>’ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-r</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> delete
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;processing commit...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">svn</span> commit</pre></div></div>

<p>Download bash script &#8211; <a href="http://files.sosedoff.com/62c99246/">http://files.sosedoff.com/62c99246/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2009/01/16/svn-auto-add-and-delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

