<?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>BigSmoke &#187; shell</title>
	<atom:link href="http://blog.bigsmoke.us/tag/shell/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bigsmoke.us</link>
	<description>Smokes your problems, coughs fresh air.</description>
	<lastBuildDate>Sat, 04 Feb 2012 18:03:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Making a shell-script run with setuid root</title>
		<link>http://blog.bigsmoke.us/2011/02/03/suid-shell-script</link>
		<comments>http://blog.bigsmoke.us/2011/02/03/suid-shell-script#comments</comments>
		<pubDate>Wed, 02 Feb 2011 22:45:50 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[setuid]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=1863</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>If you want to run a process with root privileges that you can invoke as a less unprivileged user, you can make the program setuid root. This can be very useful, for example, when you want a PHP or CGI script to call a backup process, or to create a new site or irrevocably delete you whole system. The latter example points to a serious security problem: if anyone can figure out a way to make your program do something you don&#8217;t want, you&#8217;re screwed, because you just gave them root privileges to wreak maximum havoc. That&#8217;s why, normally, scripts (anything executed by an interpreter by the kernel because of a shebang) won&#8217;t get elevated privileges when you set their setuid bit.</p>
<p>To understand the setuid bit, let&#8217;s first see what happens when I try to cat a file that belongs to root:</p>
<p><pre class="bash">su -
<span style="color: #808080; font-style: italic;"># I am now root; fear me</span>
touch no-one-can-touch-me
chmod <span style="color: #cc66cc;">600</span> no-one-can-touch-me
<span style="color: #000066;">exit</span>
cat no-one-can-touch-me
<span style="color: #808080; font-style: italic;"># cat: Permission denied </span></pre></p>
<p>Next, I&#8217;ll create a shell script that cats the file:</p>
<p><pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
&nbsp;
cat no-one-can-touch-me</pre></p>
<p>And make the script setuid root:</p>
<p><pre class="bash">su -
chown root:root script.sh
chmod +xs script.sh</pre></p>
<p>If I now execute the script, I still get the permission denied. What I need to make this work is a wrapper program. For that, I refer to Wiebe&#8217;s <a href="http://blog.bigsmoke.us/2011/02/02/executing-system-commands-from-php-with-suid-executable">post</a> about the same subject. (Yeah, I know: why bother publishing this if Wiebe already did an excellent job explaining? Well, I just hate to throw away an otherwise fine draft.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2011/02/03/suid-shell-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Goosh</title>
		<link>http://blog.bigsmoke.us/2010/06/29/goosh</link>
		<comments>http://blog.bigsmoke.us/2010/06/29/goosh#comments</comments>
		<pubDate>Tue, 29 Jun 2010 20:59:06 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Goosh]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Vimperator]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=1489</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>For a <a href="http://blog.bigsmoke.us/2009/06/07/vimperator">Vimperator user</a> like me, <a href="http://goosh.org/">Goosh</a> (the unofficial Google shell) is an obvious replacement for Google&#8217;s normal search page.</p>

<p>I&#8217;m not sure if I&#8217;ll ever really use it, because I tend to start my Google queries from Vimperator&#8217;s command-line, but nice to know that it&#8217;s there.</p>

<p>And there&#8217;s another bookmark deleted&#8230;</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2010/06/29/goosh/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing syntax errors with old shell scripts</title>
		<link>http://blog.bigsmoke.us/2010/02/14/preventing-syntax-errors-with-old-shell-scripts</link>
		<comments>http://blog.bigsmoke.us/2010/02/14/preventing-syntax-errors-with-old-shell-scripts#comments</comments>
		<pubDate>Sun, 14 Feb 2010 15:45:21 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unreal tournament]]></category>
		<category><![CDATA[ut]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=1257</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
I was trying to install Unreal Tournament GOTY on one of my Linux machines. I downloaded and ran the script <a href="http://www.filefront.com/1634336/ut-install-436-GOTY.run">ut-install-436-GOTY.run</a> but I got this error:
</p>

<pre class="php">cannot open `<span style="color: #cc66cc;">+6</span><span style="color: #ff0000;">' for reading: No such file or directory </span></pre>

<p>
This line caused it:
</p>

<pre class="php">sum1=`tail <span style="color: #cc66cc;">+6</span> $<span style="color: #cc66cc;">0</span> | cksum | sed -e <span style="color: #ff0000;">'s/ /Z/'</span> -e <span style="color: #ff0000;">'s/   /Z/'</span> | cut -dZ -f1`</pre>

<p>
To fix it, I set this environment variable:
</p>

<pre class="php">export _POSIX2_VERSION=<span style="color: #cc66cc;">199209</span></pre>

<p>
Apparently, this makes programs behave differently. Research is required to find out exactly what it does&#8230;
</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2010/02/14/preventing-syntax-errors-with-old-shell-scripts/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Wget one-liner</title>
		<link>http://blog.bigsmoke.us/2009/02/23/wget-one-liner</link>
		<comments>http://blog.bigsmoke.us/2009/02/23/wget-one-liner#comments</comments>
		<pubDate>Mon, 23 Feb 2009 19:31:14 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[one-liner]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=418</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Earlier today, I wanted to download all songs by this <a href="http://www.dehuilenderappers.nl/">totally kick-ass rap outfit</a>:</p>

<pre class="bash">wget -q -O - http://www.assheads.nl/dehuilenderappers/?<span style="color: #0000ff;">p=</span>nummers \
| sed --quiet -e <span style="color: #ff0000;">'s#^.*&lt;a href=&quot;<span style="color: #000099; font-weight: bold;">\(</span>nummers/.*<span style="color: #000099; font-weight: bold;">\.</span>mp3<span style="color: #000099; font-weight: bold;">\)</span>.*$#<span style="color: #000099; font-weight: bold;">\1</span>#p'</span> \
| sort -u \
| wget -i - -B <span style="color: #ff0000;">'http://www.assheads.nl/dehuilenderappers/'</span></pre>

<p>The same command-line, now using GNU long options to increase readability:</p>

<pre class="bash">wget --quiet --output-<span style="color: #0000ff;">document=</span>- http://www.assheads.nl/dehuilenderappers/?<span style="color: #0000ff;">p=</span>nummers \
| sed --quiet --<span style="color: #0000ff;">expression=</span><span style="color: #ff0000;">'s#^.*&lt;a href=&quot;<span style="color: #000099; font-weight: bold;">\(</span>nummers/.*<span style="color: #000099; font-weight: bold;">\.</span>mp3<span style="color: #000099; font-weight: bold;">\)</span>.*$#<span style="color: #000099; font-weight: bold;">\1</span>#p'</span> \
| sort --unique \
| wget --input-<span style="color: #0000ff;">file=</span>- --<span style="color: #0000ff;">base=</span><span style="color: #ff0000;">'http://www.assheads.nl/dehuilenderappers/'</span></pre>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/02/23/wget-one-liner/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XTerm is favorite</title>
		<link>http://blog.bigsmoke.us/2008/11/27/xterm-is-favorite</link>
		<comments>http://blog.bigsmoke.us/2008/11/27/xterm-is-favorite#comments</comments>
		<pubDate>Thu, 27 Nov 2008 21:43:42 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[X]]></category>
		<category><![CDATA[xrdb]]></category>
		<category><![CDATA[XTerm]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=108</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>XTerm is know to most X-Windows users as that ugly terminal with the strange scrollbar and the unreadable font. And it doesn&#8217;t even have tabs! But, I think it&#8217;s the best damn terminal emulator in the world. It just doesn&#8217;t appear that way at first.</p> 

<p>By default, XTerm comes with warts:</p>

<ul>
  <li>It has an ugly, small font.</li>
  <li>What&#8217;s up with the black on white? I&#8217;m a 1337 h4x0r and I want a black background, damnit!</li>
  <li>Double-click Selections is unintuitive.</li>
  <li>Where are the tabs?</li>
</ul>

<p><img src="http://blog.bigsmoke.us/wp-factory/../uploads/2008/11/bare-xterm.png" alt="Default configuration for XTerm 234" title="Default configuration for XTerm 234" width="484" height="165" class="size-full wp-image-192" /></p>

<p>But its warts are easily removed.</p>

<h2>The font is small and ugly</h2>

<p>Easily solved:</p>

<pre>
$ xrdb -merge
/* I want pretier fonts */
XTerm*faceName: Liberation Mono
XTerm*faceSize: 10
[Ctrl+D]
$ xterm
</pre>

<p><img src="http://blog.bigsmoke.us/wp-factory/../uploads/2008/11/xterm-with-nicer-fonts.png" alt="XTerm with nicer than default font" title="XTerm with nicer than default font" width="724" height="215" class="size-full wp-image-191" /></p>

<h2>The black on white is an insult to my 1337ness</h2>

<p>No longer so:</p>

<pre>
$ xrdb -merge
/* I want a 1337-style color-scheme */
XTerm*background: black
XTerm*Foreground: Grey
[Ctrl+D]
$ xterm
</pre>

<p>Now I can install my 1337 hacking tools in style! (If only I could install 1337 hacking skills as easily.)</p>

<p><img src="http://blog.bigsmoke.us/wp-factory/../uploads/2008/11/1337-style-xterm.png" alt="1337-style XTerm" title="1337-style XTerm" width="724" height="215" class="size-full wp-image-193" /></p>

<h2>Double-click selections are unintuitive</h2>

<p>Most terminal emulators let you double-click to quickly select words. XTerm does this as well, but its definition of a &#8220;word&#8221; is a bit narrow if you&#8217;re used to other programs. The good news is that XTerm is <strong>extremely configurable</strong> in this sense. It lets you decide what to select on double-click, on triple-click, all the way up to 5 clicks. You can define the boundaries of the selection by means of presets such as <q>line</q>, <q>group</q> and <q>page</q>, but what I like best is its ability to use regular expressions. This lets you do cool things, like, for example, using one click to select a word, two clicks to select a sentence, and three clicks to select a paragraph.</p>

<p>My own configuration is a bit simple, probably a testimony to how little code I write these days:</p>

<pre>$ xrdb -merge
/* The selection only stops at spaces and newlines */
XTerm*on2Clicks: regex [^  \n]+
[Ctrl+D]
</pre>

<h2>Where are my tabs</h2>

<p>You should really be using <a href="http://en.wikipedia.org/wiki/GNU_Screen">GNU Screen</a> instead, which has too many advantages to name here. It even allows you to do <a href="http://blog.bigsmoke.us/2008/07/23/pair-programming-through-gnu-screen">Remote pair programming</a> over SSH.</p>

<p>If you use Screen within an XTerm, be sure to add to following to your X configuration.</p>

<pre>$ echo "XTerm*metaSendsEscape: true" | xrdb -merge</pre>

<p>Otherwise, you might find yourself unable to control Screen

<h2>Saving your configuration</h2>

<p>Ready to save your precious configuration?</p>

<pre>
$ xrdb -edit .Xdefaults
</pre>

<p>You&#8217;re done. It&#8217;s time to go brag to your friends.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2008/11/27/xterm-is-favorite/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Disabling SSH shell access for SVN users on a Linux/Unix system</title>
		<link>http://blog.bigsmoke.us/2008/08/04/disabling-ssh-shell-access-for-svn-users-on-a-linuxunix-system</link>
		<comments>http://blog.bigsmoke.us/2008/08/04/disabling-ssh-shell-access-for-svn-users-on-a-linuxunix-system#comments</comments>
		<pubDate>Mon, 04 Aug 2008 14:01:51 +0000</pubDate>
		<dc:creator>halfgaar</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=131</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>
A common problem is that Linux/Unix system administrators want to grant users access to SVN repositories, but prevent them from logging in on the shell. This can be accomplished quite easily.
</p>

<p>
First, disable the user&#8217;s account by running:
</p>

<pre>
usermod --lock [user]
</pre>

<p>
This way, only public key authentication is allowed. Then, when adding the user&#8217;s key to the ~/.ssh/authorized_keys file, prefix it with this:
</p>

<pre>
command="/usr/local/bin/svnserve -t",no-port-forwarding,no-pty,no-agent-forwarding,no-X11-forwarding
</pre>

<p>
I used our wrapper script in /usr/local/bin as the command, because it sets an umask of 002 before actually running svnserve. This is necessary when using svn+ssh access.
</p>

<p>
<a href="http://svn.collab.net/repos/svn/trunk/notes/ssh-tricks">The source</a> for this trick explains it in more detail.
</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2008/08/04/disabling-ssh-shell-access-for-svn-users-on-a-linuxunix-system/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft batch file meets bash shellscript</title>
		<link>http://blog.bigsmoke.us/2007/06/11/microsoft-batch-file-meets-bash-shellscript</link>
		<comments>http://blog.bigsmoke.us/2007/06/11/microsoft-batch-file-meets-bash-shellscript#comments</comments>
		<pubDate>Mon, 11 Jun 2007 19:41:22 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[polyglot]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/06/11/microsoft-batch-file-meets-bash-shellscript</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Luca City, who already shared a nice <a href="http://blog.bigsmoke.us/2007/05/09/bypassing-smart-completion-in-bash">readline keyboard shortcut</a> with me, wrote me again on May 14 to share another unrelated, but very interesting trick:</p>

<blockquote><p>Hi Rowan,<br />
as you are interested in tricks and curiosities, I send you a thing.<br />
I wanted a script to be runnable from both windows and linux and I found out a way to do it.
Generally you can have two different files, one for each OS, but I started with this goal in mind and then it became a challenge. After trying a bit, playing with the strangest tricks of the two batch languages (bat and bash), I ended up with this solution.
Actually it is not so useful <img src='http://blog.bigsmoke.us/wp-factory/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  but anyway&#8230;</p></blockquote>

<p>Well Luca, regardless of the usefulness of your script, I happen to think that it&#8217;s pure genius, so I&#8217;m going to share it here:</p>

<pre class="bash"><span style="color: #000066;">echo</span> off
<span style="color: #000066;">echo</span> ; <span style="color: #000066;">set</span> +v <span style="color: #808080; font-style: italic;"># &gt; NUL</span>
<span style="color: #000066;">echo</span> ; <span style="color: #b1b100;">function</span> GOTO <span style="color: #66cc66;">&#123;</span> true; <span style="color: #66cc66;">&#125;</span> <span style="color: #808080; font-style: italic;"># &gt; NUL</span>
&nbsp;
GOTO WIN
<span style="color: #808080; font-style: italic;"># bash part, replace it to suit your needs</span>
<span style="color: #000066;">exit</span> <span style="color: #cc66cc;">0</span>
&nbsp;
:WIN
REM win part, replace it to suit your needs</pre>

<p>Give the script a <tt>.bat</tt> extension for Windows and set the executable bit(s) for Unix.</p>

<p>Thanks, Luca, for sharing another nice trick with us.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/06/11/microsoft-batch-file-meets-bash-shellscript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

