<?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>BG Tech Blog &#187; bash</title>
	<atom:link href="http://bgtechblog.com/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://bgtechblog.com</link>
	<description>Проблемите, с които се сблъскваме всеки ден</description>
	<lastBuildDate>Fri, 18 May 2012 22:33:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Елементарен скрипт за изпращане на mail през bash</title>
		<link>http://bgtechblog.com/2011/10/10/%d0%b5%d0%bb%d0%b5%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b5%d0%bd-%d1%81%d0%ba%d1%80%d0%b8%d0%bf%d1%82-%d0%b7%d0%b0-%d0%b8%d0%b7%d0%bf%d1%80%d0%b0%d1%89%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-mail-%d0%bf/</link>
		<comments>http://bgtechblog.com/2011/10/10/%d0%b5%d0%bb%d0%b5%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b5%d0%bd-%d1%81%d0%ba%d1%80%d0%b8%d0%bf%d1%82-%d0%b7%d0%b0-%d0%b8%d0%b7%d0%bf%d1%80%d0%b0%d1%89%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-mail-%d0%bf/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 12:27:57 +0000</pubDate>
		<dc:creator>Благомир Иванов</dc:creator>
				<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=614</guid>
		<description><![CDATA[#!/bin/bash SUBJECT=&#34;I am subject&#34; EMAIL=&#34;user@domain.com&#34; &#160; EMAILMESSAGE=&#34;&#34; echo &#34;Hello World&#34; &#62; $EMAILMESSAGE echo &#34;I am test text&#34; &#62;&#62; $EMAILMESSAGE &#160; /bin/mail -s &#34;$SUBJECT&#34; &#34;$EMAIL&#34; &#60; $EMAILMESSAGE No tags for this post.]]></description>
			<content:encoded><![CDATA[
<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: #007800;">SUBJECT</span>=<span style="color: #ff0000;">&quot;I am subject&quot;</span>
<span style="color: #007800;">EMAIL</span>=<span style="color: #ff0000;">&quot;user@domain.com&quot;</span>
&nbsp;
<span style="color: #007800;">EMAILMESSAGE</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hello World&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$EMAILMESSAGE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;I am test text&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$EMAILMESSAGE</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SUBJECT</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$EMAIL</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$EMAILMESSAGE</span></pre></div></div>

No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/10/10/%d0%b5%d0%bb%d0%b5%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b5%d0%bd-%d1%81%d0%ba%d1%80%d0%b8%d0%bf%d1%82-%d0%b7%d0%b0-%d0%b8%d0%b7%d0%bf%d1%80%d0%b0%d1%89%d0%b0%d0%bd%d0%b5-%d0%bd%d0%b0-mail-%d0%bf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick: mdadm check RAID</title>
		<link>http://bgtechblog.com/2011/08/09/quick-mdadm-check-raid/</link>
		<comments>http://bgtechblog.com/2011/08/09/quick-mdadm-check-raid/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 12:46:24 +0000</pubDate>
		<dc:creator>Благомир Иванов</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cent OS]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Всичко друго]]></category>
		<category><![CDATA[Защита]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=575</guid>
		<description><![CDATA[Как да накараме mdadm да ни информира ако имаме проблем с някой от RAID масивите? Елементарно: mdadm --monitor --scan --mail=MAIL@DOMAIN.com --delay=3600 --daemonize --test No tags for this post.]]></description>
			<content:encoded><![CDATA[<p>Как да накараме <em><strong>mdadm</strong></em> да ни информира ако имаме проблем с някой от RAID масивите?</p>
<p>Елементарно:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mdadm <span style="color: #660033;">--monitor</span> <span style="color: #660033;">--scan</span> <span style="color: #660033;">--mail</span>=MAIL<span style="color: #000000; font-weight: bold;">@</span>DOMAIN.com <span style="color: #660033;">--delay</span>=<span style="color: #000000;">3600</span> <span style="color: #660033;">--daemonize</span> <span style="color: #660033;">--test</span></pre></div></div>

No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/08/09/quick-mdadm-check-raid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Защита от DoS атака с iptables</title>
		<link>http://bgtechblog.com/2011/04/21/%d0%b7%d0%b0%d1%89%d0%b8%d1%82%d0%b0-%d0%be%d1%82-dos-%d0%b0%d1%82%d0%b0%d0%ba%d0%b0-%d1%81-iptables/</link>
		<comments>http://bgtechblog.com/2011/04/21/%d0%b7%d0%b0%d1%89%d0%b8%d1%82%d0%b0-%d0%be%d1%82-dos-%d0%b0%d1%82%d0%b0%d0%ba%d0%b0-%d1%81-iptables/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 15:31:54 +0000</pubDate>
		<dc:creator>Благомир Иванов</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cent OS]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Защита]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=489</guid>
		<description><![CDATA[Тези команди ще ви помогнат да се защитите от DoS атака. Посредством тях, ще блокирате всяко IP, което за 60 секунди има повече от 20 връзки (connections) към текущата машина: iptables -I INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --set &#160; iptables -I INPUT -p tcp --dport 80 -i [...]]]></description>
			<content:encoded><![CDATA[<p>Тези команди ще ви помогнат да се защитите от <a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">DoS атака</a>. Посредством тях, ще блокирате всяко IP, което за 60 секунди има повече от 20 връзки (connections) към текущата машина:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> recent <span style="color: #660033;">--set</span>
&nbsp;
iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> recent <span style="color: #660033;">--update</span> <span style="color: #660033;">--seconds</span> <span style="color: #000000;">60</span> <span style="color: #660033;">--hitcount</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> DROP</pre></div></div>

<p>Резултат от командата:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># netstat -alpn| grep &quot;:80&quot;| awk '{ print $5 }'| cut -d: -f4| sort| uniq -c | sort -n</span>
      <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span>
      <span style="color: #000000;">3</span> 66.249.72.131
     <span style="color: #000000;">16</span> 81.100.74.82
     <span style="color: #000000;">17</span> 82.12.246.158
     <span style="color: #000000;">19</span> 212.183.140.13
     <span style="color: #000000;">19</span> 78.148.123.94
     <span style="color: #000000;">20</span> 85.211.47.252
     <span style="color: #000000;">20</span> 86.166.141.234
     <span style="color: #000000;">20</span> 87.97.215.7
     <span style="color: #000000;">20</span> 89.253.191.173
     <span style="color: #000000;">20</span> 91.92.170.172
     <span style="color: #000000;">20</span> 94.156.57.170
     <span style="color: #000000;">20</span> 94.169.158.18
     <span style="color: #000000;">22</span> 77.78.11.99</pre></div></div>

<p>Разбира се това е само пример и можете да смените стоностите за секунди (60) и брои връзки (20).<br />
Имайте впредвид, че максималните стойности за <strong>&#8211;seconds</strong> са <strong>60</strong>, а за <strong>&#8211;hitcount</strong> са <strong>20</strong></p>
<p>За да премахнете правило (RULE) от iptables използвайте следните команди.<br />
Лист на всички правила в iptables:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-L</span> INPUT <span style="color: #660033;">-n</span> <span style="color: #660033;">--line-numbers</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># iptables -L INPUT -n --line-numbers</span>
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy ACCEPT<span style="color: #7a0874; font-weight: bold;">&#41;</span>
num  target     prot opt <span style="color: #7a0874; font-weight: bold;">source</span>               destination         
<span style="color: #000000;">1</span>    DROP       tcp  <span style="color: #660033;">--</span>  0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>            0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>           tcp dpt:<span style="color: #000000;">80</span> state NEW recent: UPDATE seconds: <span style="color: #000000;">60</span> hit_count: <span style="color: #000000;">20</span> name: DEFAULT side: <span style="color: #7a0874; font-weight: bold;">source</span> 
<span style="color: #000000;">2</span>               tcp  <span style="color: #660033;">--</span>  0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>            0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>           tcp dpt:<span style="color: #000000;">80</span> state NEW recent: SET name: DEFAULT side: <span style="color: #7a0874; font-weight: bold;">source</span> 
<span style="color: #000000;">3</span>    fail2ban-SSH  tcp  <span style="color: #660033;">--</span>  0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>            0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>           tcp dpt:<span style="color: #000000;">22</span> 
<span style="color: #000000;">4</span>    DROP       all  <span style="color: #660033;">--</span>  67.195.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span>        0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>           
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>server ~<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;">#</span></pre></div></div>

<p>За да изтрием правилото за блокиране на IP-тата в този случай пишем:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-D</span> INPUT <span style="color: #000000;">1</span></pre></div></div>

No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/04/21/%d0%b7%d0%b0%d1%89%d0%b8%d1%82%d0%b0-%d0%be%d1%82-dos-%d0%b0%d1%82%d0%b0%d0%ba%d0%b0-%d1%81-iptables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Брой конекции от 1 IP адрес</title>
		<link>http://bgtechblog.com/2011/04/21/%d0%b1%d1%80%d0%be%d0%b9-%d0%ba%d0%be%d0%bd%d0%b5%d0%ba%d1%86%d0%b8%d0%b8-%d0%be%d1%82-1-ip-%d0%b0%d0%b4%d1%80%d0%b5%d1%81/</link>
		<comments>http://bgtechblog.com/2011/04/21/%d0%b1%d1%80%d0%be%d0%b9-%d0%ba%d0%be%d0%bd%d0%b5%d0%ba%d1%86%d0%b8%d0%b8-%d0%be%d1%82-1-ip-%d0%b0%d0%b4%d1%80%d0%b5%d1%81/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 15:25:00 +0000</pubDate>
		<dc:creator>Благомир Иванов</dc:creator>
				<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=485</guid>
		<description><![CDATA[Как да разберем колко конекции (connections) имаме към определен порт на нашата машина. Командата дава списък с IP–та и за всяко едно от тях брои връзките, които то (IP-то) е направило към машината. Текущата команда сканира връзките към порт 80: netstat -alpn&#124; grep &#34;:80&#34;&#124; awk '{ print $5 }'&#124; cut -d: -f4&#124; sort&#124; uniq -c [...]]]></description>
			<content:encoded><![CDATA[<p>Как да разберем колко конекции (connections) имаме към определен порт на нашата машина.<br />
Командата дава списък с IP–та и за всяко едно от тях брои връзките, които то (IP-то) е направило към машината. Текущата команда сканира връзките към порт <strong>80</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-alpn</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;:80&quot;</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $5 }'</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -d: <span style="color: #660033;">-f4</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span></pre></div></div>

No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/04/21/%d0%b1%d1%80%d0%be%d0%b9-%d0%ba%d0%be%d0%bd%d0%b5%d0%ba%d1%86%d0%b8%d0%b8-%d0%be%d1%82-1-ip-%d0%b0%d0%b4%d1%80%d0%b5%d1%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tune your bash &gt; .bash_profile &#124; .bashrc &#124; ./etc/profile</title>
		<link>http://bgtechblog.com/2011/03/11/tune-your-bash-bash_profile-bashrc-etcprofile/</link>
		<comments>http://bgtechblog.com/2011/03/11/tune-your-bash-bash_profile-bashrc-etcprofile/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 10:44:44 +0000</pubDate>
		<dc:creator>vhristev</dc:creator>
				<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=375</guid>
		<description><![CDATA[This is very useful things in my Linux = .bashrc and my Mac = .bash_profile Linux = .bashrc &#124; /etc/profile I just found this useful link with .bashrc examples bashrc examples I use &#8220;HISTTIMEFORMAT=&#8217;%F %T &#8216; &#8221; Here is full list for timestamps TIMESTAMPS Here is my HISTORY section in .bashrc # don't put duplicate [...]]]></description>
			<content:encoded><![CDATA[<p>This is very useful things in my Linux = .bashrc and my Mac = .bash_profile</p>
<p>Linux = .bashrc | /etc/profile</p>
<p>I just found this useful link with .bashrc examples <a href="http://dotfiles.org/.bashrc">bashrc examples</a><br />
I use &#8220;HISTTIMEFORMAT=&#8217;%F %T &#8216; &#8221;<br />
Here is full list for timestamps  <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html">TIMESTAMPS</a></p>
<p>Here is my HISTORY section in <em><strong>.bashrc </strong></em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># don't put duplicate lines in the history. See bash(1) for more options</span>
<span style="color: #666666; font-style: italic;"># don't overwrite GNU Midnight Commander's setting of `ignorespace'.</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=<span style="color: #007800;">$HISTCONTROL</span><span style="color: #800000;">${HISTCONTROL+,}</span>ignoredups
<span style="color: #666666; font-style: italic;"># ... or force ignoredups and ignorespace</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=ignoreboth
&nbsp;
<span style="color: #666666; font-style: italic;"># append to the history file, don't overwrite it</span>
<span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> histappend
&nbsp;
<span style="color: #666666; font-style: italic;"># for setting history length see HISTSIZE and HISTFILESIZE in bash(1)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check the window size after each command and, if necessary,</span>
<span style="color: #666666; font-style: italic;"># update the values of LINES and COLUMNS.</span>
<span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> checkwinsize</pre></div></div>

<p><em><strong>/etc/profile</strong></em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> PATH
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTTIMEFORMAT</span>=<span style="color: #ff0000;">'%F %T '</span>
<span style="color: #007800;">HISTSIZE</span>=<span style="color: #000000;">100000</span>        <span style="color: #666666; font-style: italic;"># history size use big motherfucker size</span>
<span style="color: #007800;">HISTFILESIZE</span>=<span style="color: #000000;">1000</span>      <span style="color: #666666; font-style: italic;"># file log size</span>
<span style="color: #007800;">HISTCONTROL</span>=erasedups <span style="color: #666666; font-style: italic;"># dont dublucate </span>
<span style="color: #007800;">HISTCONTROL</span>=ignorespace <span style="color: #666666; font-style: italic;">#ignorepsaces</span>
<span style="color: #007800;">DATA</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span>                   <span style="color: #666666; font-style: italic;"># variable for `date`</span>
&nbsp;
<span style="color: #007800;">HISTFILE</span>=~<span style="color: #000000; font-weight: bold;">/</span>.bash_history.<span style="color: #007800;">$DATA</span>  <span style="color: #666666; font-style: italic;"># histfile will look .bash_histori + command `date`</span></pre></div></div>

<p>Here is something very useful for me and i put it in my <strong>.bashrc</strong><br />
1. random pass generator<br />
2. simple console calculator<br />
3. colours<br />
4. easy access servers with alias</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">genpasswd<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: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">l</span>=<span style="color: #007800;">$1</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$l</span>&quot;</span> == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #007800;">l</span>=<span style="color: #000000;">20</span> 
        <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-dc</span> A-Za-z0-<span style="color: #000000;">9</span>-<span style="color: #000000; font-weight: bold;">!@%</span>^<span style="color: #000000; font-weight: bold;">*</span>_ <span style="color: #000000; font-weight: bold;">&amp;</span>lt; <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;">head</span> <span style="color: #660033;">-c</span> <span style="color: #800000;">${l}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> calc <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: #7a0874; font-weight: bold;">&#123;</span> <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: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span>; <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ls</span>=<span style="color: #ff0000;">'ls --color'</span>
<span style="color: #666666; font-style: italic;"># i want my grep to color my search word and exclude my grep command</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">grep</span>=<span style="color: #ff0000;">'grep -v grep | grep --color=auto'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">fgrep</span>=<span style="color: #ff0000;">'fgrep --color=auto'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">egrep</span>=<span style="color: #ff0000;">'egrep --color=auto'</span></pre></div></div>

<p>Lets see it in action :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14</span>:<span style="color: #000000;">21</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>vhristev<span style="color: #000000; font-weight: bold;">@</span>hristev:~$ genpasswd
nHwl<span style="color: #000000; font-weight: bold;">*</span>W8Yp4v__T-whmn2
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14</span>:<span style="color: #000000;">21</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>vhristev<span style="color: #000000; font-weight: bold;">@</span>hristev:~$ calc <span style="color: #000000;">54</span>-<span style="color: #000000;">4</span>
<span style="color: #000000;">50</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14</span>:<span style="color: #000000;">21</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>vhristev<span style="color: #000000; font-weight: bold;">@</span>hristev:~$ <span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> nginx
root      <span style="color: #000000;">1920</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.2</span>  <span style="color: #000000;">27772</span>  <span style="color: #000000;">1084</span> ?        Ss   Mar10   <span style="color: #000000;">0</span>:00 nginx: master process <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>nginx
www-data  <span style="color: #000000;">1921</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.4</span>  <span style="color: #000000;">28700</span>  <span style="color: #000000;">2416</span> ?        S    Mar10   <span style="color: #000000;">0</span>:01 nginx: worker process
www-data  <span style="color: #000000;">1922</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.4</span>  <span style="color: #000000;">28536</span>  <span style="color: #000000;">2280</span> ?        S    Mar10   <span style="color: #000000;">0</span>:01 nginx: worker process
www-data  <span style="color: #000000;">1925</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.4</span>  <span style="color: #000000;">28536</span>  <span style="color: #000000;">2244</span> ?        S    Mar10   <span style="color: #000000;">0</span>:02 nginx: worker process
www-data  <span style="color: #000000;">1926</span>  <span style="color: #000000;">0.0</span>  <span style="color: #000000;">0.4</span>  <span style="color: #000000;">28536</span>  <span style="color: #000000;">2252</span> ?        S    Mar10   <span style="color: #000000;">0</span>:02 nginx: worker process
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">14</span>:<span style="color: #000000;">22</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>vhristev<span style="color: #000000; font-weight: bold;">@</span>hristev:~$</pre></div></div>

<p style="text-align: center"><a href="http://bgtechblog.com/wp-content/uploads/2011/03/bash1.jpg"><img class="size-full wp-image-385 aligncenter" src="http://bgtechblog.com/wp-content/uploads/2011/03/bash1.jpg" alt="" width="548" height="328" /></a></p>
<p>Why I need put colors in my prompt ?<br />
- We are humans and make mistakes.I remember one day how I execute command on different server and &#8230; in fact it was not so big deal but if it was ???<br />
- If you have 1-2 machines its not so useful but if you have 10 or more you may want to put some RED or YELLOW color in your prompt to identify your important servers.</p>
<p>\A &#8211; the current time in 24-hour HH:MM format<br />
33[00;31m &#8211; RED<br />
33[01;32m &#8211; Yellow</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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;">$color_prompt</span>&quot;</span> = <span style="color: #c20cb9; font-weight: bold;">yes</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">'${debian_chroot:+($debian_chroot)}\[33[00;31m\]\u@\[33[01;32m\]\h\[33[00m\]:\[33[01;34m\]\w\[33[00m\]\$ '</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">'${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">unset</span> color_prompt force_color_prompt
&nbsp;
<span style="color: #666666; font-style: italic;"># If this is an xterm set the title to user@host:dir</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
xterm<span style="color: #000000; font-weight: bold;">*|</span>rxvt<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">&quot;\[33[0;35m\]\[33[01;33m\][\A]\[\e]0;<span style="color: #007800;">${debian_chroot:+($debian_chroot)}</span>\u@\h: \w\a\]<span style="color: #007800;">$PS1</span>&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: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></div></div>

<p>And voalaaa&#8230; you get the prettiest bash prompt :<br />
You can see another idea for customize your PS1 prompt</p>
<p style="text-align: center"><a href="http://bgtechblog.com/wp-content/uploads/2011/03/Colored.jpg"><img class="size-full wp-image-383 aligncenter" src="http://bgtechblog.com/wp-content/uploads/2011/03/Colored.jpg" alt="" width="548" height="328" /></a></p>
<p>I want to access my servers very easy without typing every time USER/HOSTNAME/PORT in this case i use aliases<br />
syntax=  &#8220;alias  NAME_OF_COMMAND=&#8217;real command&#8217;<br />
example= alias  homepc=&#8217;ssh -l root 192.168.10.10 -p 3333&#8242;</p>
<p>Now when i put this in my ~/.bashrc and update it (source ~/.bashrc) when i type &#8220;homepc&#8221; command &#8220;ssh -l root 192.168.10.10 -p 3333&#8243; will be executed<br />
In action:</p>
<p style="text-align: center"><a href="http://bgtechblog.com/wp-content/uploads/2011/03/aliases.jpg"><img class="aligncenter" src="http://bgtechblog.com/wp-content/uploads/2011/03/aliases.jpg" alt="" width="548" height="328" /></a></p>
<p>Bash special characters codes</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">*</span> \a : an ASCII bell character <span style="color: #7a0874; font-weight: bold;">&#40;</span>07<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \d : the <span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;Weekday Month Date&quot;</span> format <span style="color: #7a0874; font-weight: bold;">&#40;</span>e.g., <span style="color: #ff0000;">&quot;Tue May 26&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \D<span style="color: #7a0874; font-weight: bold;">&#123;</span>format<span style="color: #7a0874; font-weight: bold;">&#125;</span> : the format is passed to strftime<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> and the result is inserted into the prompt string; an empty format results <span style="color: #000000; font-weight: bold;">in</span> a locale-specific <span style="color: #000000; font-weight: bold;">time</span> representation. The braces are required
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \e : an ASCII escape character <span style="color: #7a0874; font-weight: bold;">&#40;</span>033<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \h : the <span style="color: #c20cb9; font-weight: bold;">hostname</span> up to the first <span style="color: #ff0000;">'.'</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \H : the <span style="color: #c20cb9; font-weight: bold;">hostname</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \j : the number of <span style="color: #7a0874; font-weight: bold;">jobs</span> currently managed by the shell
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \l : the <span style="color: #c20cb9; font-weight: bold;">basename</span> of the shell’s terminal device name
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \n : newline
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \r : carriage <span style="color: #7a0874; font-weight: bold;">return</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \s : the name of the shell, the <span style="color: #c20cb9; font-weight: bold;">basename</span> of <span style="color: #007800;">$0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>the portion following the final slash<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \t : the current <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">24</span>-hour HH:MM:SS format
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \T : the current <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">12</span>-hour HH:MM:SS format
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \<span style="color: #000000; font-weight: bold;">@</span> : the current <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">12</span>-hour am<span style="color: #000000; font-weight: bold;">/</span>pm format
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \A : the current <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">24</span>-hour HH:MM format
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \u : the username of the current user
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \v : the version of <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>e.g., <span style="color: #000000;">2.00</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \V : the release of <span style="color: #c20cb9; font-weight: bold;">bash</span>, version + <span style="color: #c20cb9; font-weight: bold;">patch</span> level <span style="color: #7a0874; font-weight: bold;">&#40;</span>e.g., 2.00.0<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \<span style="color: #c20cb9; font-weight: bold;">w</span> : the current working directory, with <span style="color: #007800;">$HOME</span> abbreviated with a tilde
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \W : the <span style="color: #c20cb9; font-weight: bold;">basename</span> of the current working directory, with <span style="color: #007800;">$HOME</span> abbreviated with a tilde
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \<span style="color: #000000; font-weight: bold;">!</span> : the <span style="color: #7a0874; font-weight: bold;">history</span> number of this <span style="color: #7a0874; font-weight: bold;">command</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \<span style="color: #666666; font-style: italic;"># : the command number of this command</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \$ : <span style="color: #000000; font-weight: bold;">if</span> the effective UID is <span style="color: #000000;">0</span>, a <span style="color: #666666; font-style: italic;">#, otherwise a $</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \nnn : the character corresponding to the octal number nnn
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \\ : a backslash
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \<span style="color: #7a0874; font-weight: bold;">&#91;</span> : begin a sequence of non-printing characters, <span style="color: #c20cb9; font-weight: bold;">which</span> could be used to embed a terminal control sequence into the prompt
&nbsp;
    <span style="color: #000000; font-weight: bold;">*</span> \<span style="color: #7a0874; font-weight: bold;">&#93;</span> : end a sequence of non-printing characters</pre></div></div>

<p style="text-align: center"><a href="http://bgtechblog.com/wp-content/uploads/2011/03/aliases.jpg"></a></p>
<p>Here is my MacBook<strong> <em>.bash_profile </em></strong> some good function ps and grep some process example = psgrep apache  will ps aux | grep apache .</p>
<p style="text-align: center"><a href="http://bgtechblog.com/wp-content/uploads/2011/03/osx.jpg"><img class="size-full wp-image-387 aligncenter" src="http://bgtechblog.com/wp-content/uploads/2011/03/osx.jpg" alt="" width="548" height="328" /></a></p>
No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/03/11/tune-your-bash-bash_profile-bashrc-etcprofile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to Generate/Upload ssh key to remote system</title>
		<link>http://bgtechblog.com/2011/03/09/generateupload-ssh-key-to-system-script/</link>
		<comments>http://bgtechblog.com/2011/03/09/generateupload-ssh-key-to-system-script/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 20:14:12 +0000</pubDate>
		<dc:creator>vhristev</dc:creator>
				<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=350</guid>
		<description><![CDATA[This is script who will generate or upload ssh key to remote system 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [...]]]></description>
			<content:encoded><![CDATA[<p>This is script who will generate or upload ssh key to remote system</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td 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;"># This was written only for simple usage</span>
<span style="color: #666666; font-style: italic;">#Valentin Hristev</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### Enter username and IP(or hostname) for REMOTE machine</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter remote username: &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> USR
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Remote username is set to <span style="color: #007800;">$USR</span>  &quot;</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$usr</span> <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter remote ip/host address: &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> HOST
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Remote ip/host is set to <span style="color: #007800;">$HOST</span>  &quot;</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$usr</span> <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#echo -n &quot;Default SSH port is 22 if you want to change it please open ssh_gen with your favourite text editor and change &quot;PORT=&quot; PORT_NUMMER&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter PORT: &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> PORT
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Remote port is <span style="color: #007800;">$PORT</span>  &quot;</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$usr</span> <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Your config is :User = <span style="color: #007800;">$USR</span>  Host = <span style="color: #007800;">$HOST</span> Port = <span style="color: #007800;">$PORT</span> &quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#PORT=&quot;22&quot;</span>
<span style="color: #007800;">NEWKEY</span>=<span style="color: #ff0000;">&quot;yes&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Generate SSH keys RSA</span>
makekey <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: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NEWKEY</span> == <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>identity
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check for file &quot;authozed_keys&quot; if file is not there create it.</span>
&nbsp;
checkfile <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: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check for &quot;.ssh&quot; if dir is not there create it.</span>
upload <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;">cat</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>identity.pub <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$PORT</span> <span style="color: #007800;">$USR</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$HOST</span> <span style="color: #ff0000;">'sh -c &quot;if [ ! -d .ssh ] ; then mkdir .ssh ; chmod 700 .ssh ; fi
cat - &amp;gt;&amp;gt;~/.ssh/authorized_keys &amp;amp;&amp;amp; chmod 600 ~/.ssh/authorized_keys&quot;'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done..................... &quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Main Menu</span>
press_enter <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: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Press Enter to continue&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">selection</span>=
<span style="color: #000000; font-weight: bold;">until</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$selection</span>&quot;</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;">do</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;*******PROGRAM MENU&quot;</span><span style="color: #000000; font-weight: bold;">**********</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;1 - Generate &amp;amp; Upload New Key&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;2 - Upload Old Key&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0 - exit &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter choose: &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> selection
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$selection</span> <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> checkfile ; makekey ; upload <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> upload <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
    <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;Please enter 1, 2 or 0&quot;</span>; press_enter
&nbsp;
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#END</span></pre></td></tr></table></div>

<p>Here is script in action</p>
<p><a href="http://bgtechblog.com/wp-content/uploads/2011/03/Screen-shot-2011-03-09-at-10.04.53-PM.png"><img class="alignnone size-full wp-image-355" src="http://bgtechblog.com/wp-content/uploads/2011/03/Screen-shot-2011-03-09-at-10.04.53-PM.png" alt="" width="906" height="798" /></a></p>
No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/03/09/generateupload-ssh-key-to-system-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Как да убием всички процеси по ключова дума?</title>
		<link>http://bgtechblog.com/2011/02/11/%d0%ba%d0%b0%d0%ba-%d0%b4%d0%b0-%d1%83%d0%b1%d0%b8%d0%b5%d0%bc-%d0%b2%d1%81%d0%b8%d1%87%d0%ba%d0%b8-%d0%bf%d1%80%d0%be%d1%86%d0%b5%d1%81%d0%b8-%d0%bf%d0%be-%d0%ba%d0%bb%d1%8e%d1%87%d0%be%d0%b2%d0%b0/</link>
		<comments>http://bgtechblog.com/2011/02/11/%d0%ba%d0%b0%d0%ba-%d0%b4%d0%b0-%d1%83%d0%b1%d0%b8%d0%b5%d0%bc-%d0%b2%d1%81%d0%b8%d1%87%d0%ba%d0%b8-%d0%bf%d1%80%d0%be%d1%86%d0%b5%d1%81%d0%b8-%d0%bf%d0%be-%d0%ba%d0%bb%d1%8e%d1%87%d0%be%d0%b2%d0%b0/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 08:18:31 +0000</pubDate>
		<dc:creator>Благомир Иванов</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=320</guid>
		<description><![CDATA[При преглед на една от машините днес забелязах, че един cron е останал висящ в опашката и са зависнали близо 60 негови изпълнения. user 312 0.0 0.0 60376 7164 ? Ss Jan14 1:26 /usr/local/php/bin/php /www/domain.com/www/root/dumper.php user 635 0.0 0.0 60000 7476 ? Ss 2010 2:24 /usr/local/php/bin/php /www/domain.com/www/root/dumper.php user 740 0.0 0.0 60000 6656 ? Ss [...]]]></description>
			<content:encoded><![CDATA[<p>При преглед на една от машините днес забелязах, че един cron е останал висящ в опашката и са зависнали близо 60 негови изпълнения.<br />
<code>user    312  0.0  0.0  60376  7164 ?        Ss   Jan14   1:26 /usr/local/php/bin/php /www/domain.com/www/root/dumper.php<br />
user    635  0.0  0.0  60000  7476 ?        Ss    2010   2:24 /usr/local/php/bin/php /www/domain.com/www/root/dumper.php<br />
user    740  0.0  0.0  60000  6656 ?        Ss    2010   2:29 /usr/local/php/bin/php<br />
.............<br />
</code></p>
<p>За да убия всичките процеси наведнъж и да не пиша отделно PID на всеки процес, използвах следната команта:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> dumper <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p>Въпросната команда обикала дървото с процесите и навсякъде където срещне думата &#8220;dumper&#8221; kill-ва процеса.</p>
No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2011/02/11/%d0%ba%d0%b0%d0%ba-%d0%b4%d0%b0-%d1%83%d0%b1%d0%b8%d0%b5%d0%bc-%d0%b2%d1%81%d0%b8%d1%87%d0%ba%d0%b8-%d0%bf%d1%80%d0%be%d1%86%d0%b5%d1%81%d0%b8-%d0%bf%d0%be-%d0%ba%d0%bb%d1%8e%d1%87%d0%be%d0%b2%d0%b0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>bash script за бекъп (backup) на база данни</title>
		<link>http://bgtechblog.com/2009/11/14/bash-script-%d0%b7%d0%b0-%d0%b1%d0%b5%d0%ba%d1%8a%d0%bf-backup-%d0%bd%d0%b0-%d0%b1%d0%b0%d0%b7%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d0%b8/</link>
		<comments>http://bgtechblog.com/2009/11/14/bash-script-%d0%b7%d0%b0-%d0%b1%d0%b5%d0%ba%d1%8a%d0%bf-backup-%d0%bd%d0%b0-%d0%b1%d0%b0%d0%b7%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d0%b8/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 09:44:07 +0000</pubDate>
		<dc:creator>Благомир Иванов</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Lab]]></category>

		<guid isPermaLink="false">http://bgtechblog.com/?p=178</guid>
		<description><![CDATA[В момента съм в процес на ъпгрейд на бекъп системата ми. Не се учудвайте ако видите нещо да е &#8220;не както трябва&#8221;, защото все пак цялата система е писана за лични нужди и скоро няма изгледи да бъде пусната за масово ползване. За пореден път: авторите на блога не отговарят за щетите, които може да [...]]]></description>
			<content:encoded><![CDATA[<p>В момента съм в процес на ъпгрейд на бекъп системата ми. Не се учудвайте ако видите нещо да е &#8220;не както трябва&#8221;, защото все пак цялата система е писана за лични нужди и скоро няма изгледи да бъде пусната за масово ползване.</p>
<p><em>За пореден път: авторите на блога не отговарят за щетите, които може да нанесете на системата си, използвайки и прилагайки статиите написани тук!</em></p>
<p>Ето го и скрипта <img src='http://bgtechblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">DBUSER</span>=<span style="color: #ff0000;">&quot;root&quot;</span>
<span style="color: #007800;">DBPASS</span>=<span style="color: #ff0000;">&quot;password_here&quot;</span>
<span style="color: #007800;">DIR</span>=<span style="color: #ff0000;">&quot;/home/blagomir/test/&quot;</span>
<span style="color: #007800;">DUMP</span>=<span style="color: #ff0000;">&quot;/usr/bin/mysqldump&quot;</span>
&nbsp;
&nbsp;
<span style="color: #007800;">DATABASES</span>=<span style="color: #000000; font-weight: bold;">`</span>mysql <span style="color: #660033;">-u</span> <span style="color: #007800;">$DBUSER</span> -p<span style="color: #007800;">$DBPASS</span> <span style="color: #660033;">-e</span><span style="color: #ff0000;">&quot;show databases&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">for</span> b <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$DATABASES</span> ;
	<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">TABLES</span>=<span style="color: #000000; font-weight: bold;">`</span>mysql <span style="color: #660033;">-u</span> <span style="color: #007800;">$DBUSER</span> -p<span style="color: #007800;">$DBPASS</span> <span style="color: #660033;">-e</span><span style="color: #ff0000;">&quot;show tables from <span style="color: #007800;">$b</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup database <span style="color: #007800;">$b</span>&quot;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$TABLES</span> ;
	<span style="color: #000000; font-weight: bold;">do</span>
&nbsp;
		<span style="color: #007800;">VARIABLE</span>=<span style="color: #ff0000;">&quot;Tables_in_<span style="color: #007800;">$b</span>&quot;</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: #ff0000;">&quot;<span style="color: #007800;">$VARIABLE</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #007800;">$t</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;Backup table <span style="color: #007800;">$b</span>.<span style="color: #007800;">$t</span>&quot;</span>
			<span style="color: #007800;">$DUMP</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$DBUSER</span> -p<span style="color: #007800;">$DBPASS</span> <span style="color: #660033;">--database</span> <span style="color: #007800;">$b</span> <span style="color: #660033;">--table</span> <span style="color: #007800;">$t</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$DIR</span><span style="color: #007800;">$b</span>.<span style="color: #007800;">$t</span>.sql
		<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done backup <span style="color: #007800;">$b</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://bgtechblog.com/2009/11/14/bash-script-%d0%b7%d0%b0-%d0%b1%d0%b5%d0%ba%d1%8a%d0%bf-backup-%d0%bd%d0%b0-%d0%b1%d0%b0%d0%b7%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d0%b8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

