<?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>logIt &#187; shell script</title>
	<atom:link href="https://lakm.us/logit/tag/shell-script/feed/" rel="self" type="application/rss+xml" />
	<link>https://lakm.us/logit</link>
	<description>Log Around The Clock</description>
	<lastBuildDate>Sat, 06 Jun 2015 14:17:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Raspberry Pi: Membrane (Matrix) Keypad as GPIO Input</title>
		<link>https://lakm.us/logit/2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/</link>
		<comments>https://lakm.us/logit/2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 08:55:13 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[ARM Linux]]></category>
		<category><![CDATA[ARMv6]]></category>
		<category><![CDATA[embedded system]]></category>
		<category><![CDATA[GPIO]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[shell script]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=533</guid>
		<description><![CDATA[Membrane matrix keypad using GPIO as Raspberry Pi input has been my goal since WiringPi deployed in the first place. To begin with, GPIO hacking was initially started with some important basics (see previous post). Without external system (other interfacing chip), the 3&#215;4 membrane keypad reserved all seven GPIO pins plus one pin used for [...]]]></description>
				<content:encoded><![CDATA[<p>Membrane matrix keypad using GPIO as <a href="http://www.raspberrypi.org" target="_blank">Raspberry Pi</a> input has been my goal since <em><a href="https://projects.drogon.net/raspberry-pi/wiringpi/" target="_blank">WiringPi</a></em> deployed in the first place. To begin with, GPIO hacking was initially started with some important basics (see <a href="./2013/03/raspberry-pi-gpio-input-button-basics-1/" target="_blank">previous post</a>). Without external system (other interfacing chip), the <a href="http://www.adafruit.com/products/419" title="Similar product from Adafruit: Membrane Matrix Keypad 3x4" target="_blank">3&#215;4 membrane keypa</a>d reserved all seven GPIO pins plus one pin used for LED indicating successful reading of pressed key.</p>
<p><time datetime="2014-02-09"><br />
<blockquote style="background-color:lightyellow;"><strong><em>Updated:</em></strong> for those who fail to build using <a href="https://github.com/WiringPi/WiringPi-Python" title="WiringPi-Python" target="_blank">deprecated WiringPi-Python</a>, check <a href="../../2013/03/raspberry-pi-gpio-input-button-basics-1/" title="Raspberry Pi GPIO Input Button Basics" target="_blank">this updated post</a> to know which commit that build without error. There is now also <a href="../../2014/02/any-m-x-n-matrix-keypad-raspberry-pi/" title="Any m-by-n Matrix Keypad for Raspberry Pi" target="_blank">a Python class for matrix keypad</a>.</p></blockquote>
<p></time></p>
<p>My idea of having the keypad is to make alternative input available under no keyboard presence nor shell access. List of things I can think of for instances, pressed key &#8220;0&#8243; will make the Raspberry Pi (RPi) dial GPRS to a specific ISP and act as router to the USB WiFi stick, pressed key &#8220;7&#8243; will convert it to a router that will bridge the ethernet to WiFi, etc. In short, those key readings will invoke subsequent scripts to run inside RPi.</p>
<p>The physical connection schematic drawings and code are gitified (visit <a href="https://github.com/bandono/matrixQPi/tree/v1.2" title="gitHub: matrixQPi v1.2" target="_blank">v1.2 of the project on gitHub</a>). A nice animated image on how the buttons connect pins forming a matrix can be found in <a href="http://www.hackyourmind.org/blog/rpi-hw-interfacing-the-raspberry-pi-with-matrix-keypad/" target="_blank">hackyourmind.org</a>.</p>
<div class="wp-caption aligncenter" style="width: 460px"><a href="http://www.flickr.com/photos/aqila_rifti/8541074196/" title="Raspberry #Pi membrane (matrix) keypad. Longer hours with the circuitry in fear of bricking it. The code took half day of work instead by aqila_rifti, on Flickr"><img src="http://farm9.staticflickr.com/8375/8541074196_a22dccbd2a.jpg" width="310" height="310" alt="Raspberry #Pi membrane (matrix) keypad. Longer hours with the circuitry in fear of bricking it. The code took half day of work instead"></a> <p class="wp-caption-text">Matrix keypad: alternative quick input for Raspberry Pi to start certain command</p></div>
<p>Some remarks over what the code does:<br />
<span id="more-533"></span></p>
<ul>
<li>It only read one pressed key at a time.</li>
<li>It uses no interrupt. To read input it must wait and scan (this waiting experience is by far negligible to human sense).</li>
<li>Debouncing doesn&#8217;t seem necessary as <em>WiringPi</em> already provided this by software (I suppose <a href="https://github.com/WiringPi/WiringPi/blob/master/examples/wfi.c" title="WiringPi: wfi.c" target="_blank">this timing method on their gitHub</a> deals with debounce).</li>
</ul>
<p>How it works? <a href="http://www.raspberrypi.org/phpBB3/viewtopic.php?t=30376&#038;p=291617" title="RPi Forum: Membrane Keypad Circuit Help" target="_blank">RPi forum thread</a> gives a general idea that applies in my case:</p>
<ol>
<li>Divide the 3&#215;4 matrix as columns and rows. 4 GPIO pins as rows are pulled-up with 10k resistors and initialized as input.</li>
<li>Other 3 GPIO pins as columns are initialized as output low.</li>
<li>First loop will scan for one pressed key being read as one of the rows pulled-low</li>
<li>After the loop breaks, all columns are set as input, then the row pin found in the loop is set as output-high</li>
<li>Second loop will scan for column being pulled-high by that row pin. Between both loops, it is assumed that the key press is still in effect. In reality, normal human act of pressing this key elapses long enough for the software to run the scans in two loops.</li>
<li>Bingo! The code reads row-column combination of the pressed key.</li>
</ol>
<p>Example of the code&#8217;s output by calling from shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</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>matrixQPi.py -i; <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000;">3</span>
<span style="color: #000000;">6</span>
<span style="color: #000000;">9</span>
<span style="color: #000000;">8</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>(In the above example <code>^C</code> will throw Python <code>KeyboardInterrupt</code> messages before  breaking the <code>bash</code> loop)</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2013/03/raspberry-pi-membrane-matrix-keypad-gpio-input-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alas my LinkedIn password is in the file! (Howto check compromised password)</title>
		<link>https://lakm.us/logit/2012/06/alas-linkedin-password-file-howto-check-compromised-password/</link>
		<comments>https://lakm.us/logit/2012/06/alas-linkedin-password-file-howto-check-compromised-password/#comments</comments>
		<pubDate>Tue, 12 Jun 2012 08:59:10 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[socialmedia]]></category>

		<guid isPermaLink="false">http://lakm.us/logit/?p=393</guid>
		<description><![CDATA[When LinkedIn privacy breach was about to be revealed during Yuval Ne&#8217;eman workshop in Tel Aviv University, suddenly the timeline trends were that of friends, telling people to change LinkedIn password. Both were separate issues and of course the privacy breach was then subsided from people&#8217;s attention. To tell you the truth, as a secret [...]]]></description>
				<content:encoded><![CDATA[<p>When <a href="http://blog.skycure.com/2012/06/linkedout-linkedin-privacy-issue.html" title="LinkedOut - A LinkedIn Privacy Issue" target="_blank">LinkedIn privacy breach</a> was about to be revealed during Yuval Ne&#8217;eman workshop in Tel Aviv University, suddenly the timeline trends were that of friends, telling people to <a href="http://blog.linkedin.com/2012/06/06/linkedin-member-passwords-compromised/" title="LinkedIn Blog" target="_blank">change LinkedIn password</a>. Both were separate issues and of course the privacy breach was then subsided from people&#8217;s attention. To tell you the truth, as a secret admirer of conspiracy theory (whether I admit it or not), this coincident was just too perfectly timed. But, I&#8217;m also curious whether my password was among the stolen 6,458,020 (yes: 6,4 millions) uploaded by the hacker in hashed <a href="http://en.wikipedia.org/wiki/SHA-1" title="http://en.wikipedia.org/wiki/SHA-1" target="_blank">SHA-1</a> without the user name.</p>
<div class="wp-caption alignnone" style="width: 460px"><a href="http://blog.skycure.com/2012/06/linkedout-linkedin-privacy-issue.html"><img alt="linkedin-uploading-contact-resized-skycure-dot-com.png" src="../../../../images/linkedin-uploading-contact-resized-skycure-dot-com.png" title="Snapshot of uploaded contact data from calendar (skycure.com)" width="420" height="197" /></a><p class="wp-caption-text">Snapshot of uploaded contact data from calendar (skycure.com)</p></div>
<p>There is not other way but to check my password against the <code>combo_not.txt</code> found via <a href="http://www.filestube.com/" title="Filestube.com" target="_blank">Filestube</a>. People already posted howto check this, the easiest way is doing <a href="http://news.ycombinator.com/item?id=4076768" title="Y Hacker News" target="_blank">a single line in the shell</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">printf</span> bandito <span style="color: #000000; font-weight: bold;">|</span> openssl sha1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c10-</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-f</span> - combo_not.txt
00000d40df69b72328229d2425714f40d7d9a7a3</pre></div></div>

<p>Bingo! a match there for the password &#8220;bandito&#8221; (I choose this randomly expecting some person out there is using it). Another way (for comparison as I&#8217;m no security expert) is by this short python script (slightly altered from <a href="http://wordpress.phobostechnology.com/?p=149" title="LinkedIn Passwords – Change them" target="_blank">Phobos Technology blog post</a>):</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
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;&quot;&quot;
Save this file as linkedin_hash.py and ensure it's
in the same folder as combo_not.txt
Usage: python linkedin_hash.py hunter2
&quot;&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">from</span> hashlib <span style="color: #ff7700;font-weight:bold;">import</span> sha1
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
password = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
hsh = sha1<span style="color: black;">&#40;</span>password<span style="color: black;">&#41;</span>.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;SHA-1: %s&quot;</span> <span style="color: #66cc66;">%</span> hsh
x = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'combo_not.txt'</span>,<span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> hsh == line.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        x += <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #483d8b;">&quot;00000&quot;</span> + hsh<span style="color: black;">&#91;</span><span style="color: #ff4500;">5</span>:<span style="color: black;">&#93;</span> == line.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        x += <span style="color: #ff4500;">1</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Matching line: %s&quot;</span> <span style="color: #66cc66;">%</span> line
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Number of matches: %d&quot;</span> <span style="color: #66cc66;">%</span> x</pre></td></tr></table></div>

<p>My verdict is: <strong>my password is on the list</strong> and I&#8217;m considering a leap of faith from devoted conspiracy believer.</p>
<p>PS: I don&#8217;t find that &#8220;password&#8221; or &#8220;123456&#8243; as common passwords used by many people.<br />
PPS: A side story: Indonesians are found to be using weakest passwords (as <a href="http://bit.ly/JGECVM" title="Indonesia has weakest computer passwords: Researcher | The Jakarta Post">research over Yahoo ID revealed</a>)</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2012/06/alas-linkedin-password-file-howto-check-compromised-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Function Return Value ?</title>
		<link>https://lakm.us/logit/2009/03/function-return-value/</link>
		<comments>https://lakm.us/logit/2009/03/function-return-value/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 07:42:19 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General Linux]]></category>
		<category><![CDATA[shell script]]></category>

		<guid isPermaLink="false">http://localhost/it/?p=53</guid>
		<description><![CDATA[The following function: 1 2 3 processLine&#40;&#41;&#123; &#60;strong&#62;line&#60;/strong&#62;=&#34;$@&#34; &#125; Does it have some sort of &#8220;return value&#8221;? (in this case the variable line) by calling it through: processLine $line echo $line In the above example, I echo the value of line after being processed by processLine(). (?)]]></description>
				<content:encoded><![CDATA[<p>The following function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">processLine<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;">&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span>line<span style="color: #000000; font-weight: bold;">&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span>=<span style="color: #ff0000;">&quot;$@&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Does it have some sort of  &#8220;return value&#8221;? (in this case the variable <code>line</code>) by calling it through:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">processLine <span style="color: #007800;">$line</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$line</span></pre></div></div>

<p>In the above example, I echo the value of <code>line</code> after being processed by <code>processLine()</code>. (?)</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2009/03/function-return-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Startup script for TAP interfaces</title>
		<link>https://lakm.us/logit/2009/02/startup-script-for-tap-interfaces/</link>
		<comments>https://lakm.us/logit/2009/02/startup-script-for-tap-interfaces/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 15:31:12 +0000</pubDate>
		<dc:creator>Arif</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[startup]]></category>

		<guid isPermaLink="false">http://localhost/it/?p=8</guid>
		<description><![CDATA[To add startup script we can use: System > Preferences > Sessions local boot script (as services start/stop in /etc/init.d/) I added the following shell script: setup-tap: #! /bin/bash tap_up&#40;&#41; &#123; tunctl -t tap0 -u $USER tunctl -t tap1 -u $USER ifconfig tap0 192.168.20.1 ifconfig tap1 192.168.40.1 #iptables -t nat -A POSTROUTING -o eth1 -j [...]]]></description>
				<content:encoded><![CDATA[<p>To add startup script we can use:</p>
<ul>
<li>System > Preferences > Sessions</li>
<li>local boot script  (as  services start/stop  in  /etc/init.d/)</li>
</ul>
<p>I added the following shell script: <code>setup-tap</code>:</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>
tap_up<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>
tunctl <span style="color: #660033;">-t</span> tap0 <span style="color: #660033;">-u</span> <span style="color: #007800;">$USER</span>
tunctl <span style="color: #660033;">-t</span> tap1 <span style="color: #660033;">-u</span> <span style="color: #007800;">$USER</span>
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> tap0 192.168.20.1
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> tap1 192.168.40.1
<span style="color: #666666; font-style: italic;">#iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE</span>
sysctl <span style="color: #660033;">-w</span> net.ipv4.ip_forward=<span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
tap_down<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>
tunctl <span style="color: #660033;">-d</span> tap0
tunctl <span style="color: #660033;">-d</span> tap1
sysctl <span style="color: #660033;">-w</span> net.ipv4.ip_forward=<span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<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>
tap_up
<span style="color: #000000; font-weight: bold;">;;</span>
stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
tap_down
<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: $0 {start|stop}&quot;</span>
<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Basically it is used as <code>./setup-tap start|stop</code>.  The following steps add it to boot:<br />
copy it to <code>/etc/init.d/setup-tap<br />
</code><code>chmod +xr setup-tap</code><code><br />
update-rc.d setup-tap defaults</code><br />
The last updating will put it in default runlevel:<br />
<code>setup-tap <strong>start</strong></code> in runlevel 2,3,4, and 5 <code>setup-tap <strong>stop</strong></code> in runlevel 1 and 6.</p>
<p>Specific to this script itself, it didn&#8217;t run at first due to the <code>$USER</code> environment variable which must be set to <code>arif</code> (my username).</p>
]]></content:encoded>
			<wfw:commentRss>https://lakm.us/logit/2009/02/startup-script-for-tap-interfaces/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
