<?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>Marius van Witzenburg &#187; Shell</title>
	<atom:link href="http://mariusvw.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusvw.com</link>
	<description>We fight for our survival, we fight!</description>
	<lastBuildDate>Tue, 27 Dec 2011 10:35:27 +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>How to create SFTP-only user accounts to kill SSH access</title>
		<link>http://mariusvw.com/2011/06/15/how-to-create-sftp-only-user-accounts-to-kill-ssh-access/</link>
		<comments>http://mariusvw.com/2011/06/15/how-to-create-sftp-only-user-accounts-to-kill-ssh-access/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 16:22:25 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[Secure]]></category>
		<category><![CDATA[SFTP]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=375</guid>
		<description><![CDATA[Problem Statement We wanted to create SFTP-only user accounts that cannot SSH into the server to run commands. There is no built-in approach to this problem that we can find so we created a simple shell script to solve it. Here we will discuss how it works. Step 1: Create a shell script to run [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem Statement</strong><br />
We wanted to create SFTP-only user accounts that cannot SSH into the server to run commands. There is no built-in approach to this problem that we can find so we created a simple shell script to solve it. Here we will discuss how it works.</p>
<p><strong>Step 1: Create a shell script to run as the user’s shell</strong></p>
<p>Create a shell script called <em>/sbin/sftp-only</em> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$*&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;-c /usr/libexec/sftp-server&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> “Sorry, <span style="color: #c20cb9; font-weight: bold;">ssh</span> access not allowed.”
    <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>sftp-server</pre></div></div>

<p><strong>Step 2: Edit user accounts to use this shell script as user’s shell</strong></p>
<p>Modify user accounts using <em>usermod</em> to set the shell to <em>/sbin/sftp-only</em> so that when user tries to SSH to the server, the shell script will display the “Sorry, ssh access not allowed.” message. And when the user tries to connect to the server via a SFTP client, the shell script will get executed and it will start the SFTP server for the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/06/15/how-to-create-sftp-only-user-accounts-to-kill-ssh-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test your console if it can display 256 colors with Perl</title>
		<link>http://mariusvw.com/2011/06/12/test-your-console-if-it-can-display-256-colors-with-perl/</link>
		<comments>http://mariusvw.com/2011/06/12/test-your-console-if-it-can-display-256-colors-with-perl/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 10:44:03 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[Colors]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Terminal]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=123</guid>
		<description><![CDATA[With this script you can test which colors your console can display. You will simply see all the supported colors on your console. #!/usr/bin/perl # Author: Todd Larason &#60;jtl@molehill.org&#62; # $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $ &#160; # use the resources for colors 0-15 - usually more-or-less a # reproduction of the standard [...]]]></description>
			<content:encoded><![CDATA[<p>With this script you can test which colors your console can display.</p>
<p>You will simply see all the supported colors on your console.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #666666; font-style: italic;"># Author: Todd Larason &lt;jtl@molehill.org&gt;</span>
<span style="color: #666666; font-style: italic;"># $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># use the resources for colors 0-15 - usually more-or-less a</span>
<span style="color: #666666; font-style: italic;"># reproduction of the standard ANSI colors, but possibly more</span>
<span style="color: #666666; font-style: italic;"># pleasing shades</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># colors 16-231 are a 6x6x6 color cube</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$red</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$red</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$red</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$green</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$green</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$green</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$blue</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$blue</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$blue</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b]4;%d;rgb:%2.2x/%2.2x/%2.2x<span style="color: #000099; font-weight: bold;">\x</span>1b<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #339933;">,</span>
		   	<span style="color: #cc66cc;">16</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$red</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$green</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$blue</span><span style="color: #339933;">,</span>
		   	<span style="color: #000066;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$red</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">42.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		   	<span style="color: #000066;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$green</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">42.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		   	<span style="color: #000066;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$blue</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">42.5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># colors 232-255 are a grayscale ramp, intentionally leaving out</span>
<span style="color: #666666; font-style: italic;"># black and white</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$gray</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$gray</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">24</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$gray</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #0000ff;">$level</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$gray</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b]4;%d;rgb:%2.2x/%2.2x/%2.2x<span style="color: #000099; font-weight: bold;">\x</span>1b<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">232</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$gray</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$level</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$level</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$level</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># display the colors</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># first the system ones:</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;System colors:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$color</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$color</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$color</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[48;5;${color}m  &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[0m<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$color</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$color</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$color</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[48;5;${color}m  &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[0m<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># now the color cube</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Color cube, 6x6x6:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$green</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$green</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$green</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$red</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$red</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$red</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$blue</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$blue</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$blue</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    	<span style="color: #0000ff;">$color</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$red</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$green</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$blue</span><span style="color: #339933;">;</span>
	    	<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[48;5;${color}m  &quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[0m &quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># now the grayscale ramp</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Grayscale ramp:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$color</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">232</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$color</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">256</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$color</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[48;5;${color}m  &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>1b[0m<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/06/12/test-your-console-if-it-can-display-256-colors-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to set UTF-8 as system default on FreeBSD</title>
		<link>http://mariusvw.com/2011/06/10/how-to-set-utf-8-as-system-default-on-freebsd/</link>
		<comments>http://mariusvw.com/2011/06/10/how-to-set-utf-8-as-system-default-on-freebsd/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 06:45:32 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=67</guid>
		<description><![CDATA[Setting UTF-8 support on FreeBSD as a default is quite simple. Edit the file /etc/login.conf and add these two lines to the default block, note the trailing backslash! You need to close all lines except the last one with a backslash. :charset=UTF-8:\ :lang=en_US.UTF-8: Save the file and run the following command: /usr/bin/cap_mkdb /etc/login.conf Now logout [...]]]></description>
			<content:encoded><![CDATA[<p>Setting UTF-8 support on FreeBSD as a default is quite simple.</p>
<p>Edit the file <em>/etc/login.conf</em> and add these two lines to the default block, note the trailing backslash! You need to close all lines except the last one with a backslash.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    :<span style="color: #007800;">charset</span>=UTF-<span style="color: #000000;">8</span>:\
    :<span style="color: #007800;">lang</span>=en_US.UTF-<span style="color: #000000;">8</span>:</pre></div></div>

<p>Save the file and run the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cap_mkdb <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>login.conf</pre></div></div>

<p>Now logout and login and you have a UTF-8 aware shell <img src='http://mariusvw.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>In case you use <a href="http://www.gnu.org/software/screen/">GNU Screen</a> you should not have to worry about changes in the <em>.screensrc</em> like <em>defutf8 on</em>. Just leave them default and it should work fine.</p>
<p>In case some programs run into problems it might be required to change another line in login.conf:</p>
<p>Locate:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #007800;">setenv</span>=<span style="color: #007800;">MAIL</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>$,<span style="color: #007800;">BLOCKSIZE</span>=K,<span style="color: #007800;">FTP_PASSIVE_MODE</span>=YES:\</pre></div></div>

<p>Change to</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #007800;">setenv</span>=<span style="color: #007800;">MAIL</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>$,<span style="color: #007800;">BLOCKSIZE</span>=K,<span style="color: #007800;">FTP_PASSIVE_MODE</span>=YES,<span style="color: #007800;">LC_COLLATE</span>=C:\</pre></div></div>

<p>The above should help you out to fix UTF-8 on your SSH console and such, another thing you need to add to your kernel options is this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">options TEKEN_UTF8</pre></div></div>

<p>Note that you might need to adjust /etc/ttys and change 'cons25' to 'xterm'.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2011/06/10/how-to-set-utf-8-as-system-default-on-freebsd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shellproxy, an easy tool to run shell commands from PHP or other languages</title>
		<link>http://mariusvw.com/2010/03/02/shellproxy-an-easy-tool-to-run-shell-commands-from-php-or-other-languages/</link>
		<comments>http://mariusvw.com/2010/03/02/shellproxy-an-easy-tool-to-run-shell-commands-from-php-or-other-languages/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 19:53:02 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Return]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Value]]></category>

		<guid isPermaLink="false">http://mariusvw.com/?p=1302</guid>
		<description><![CDATA[This is a simple script that runs a shell command from PHP with the function system(). It sometimes happens that a command doesn't close the stdin or stdout, resulting the system() function to halt and wait for it to finish... This causes PHP to reach the 30 second time limit and kill the script. This [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple script that runs a shell command from PHP with the function <strong>system()</strong>.<br />
It sometimes happens that a command doesn't close the <strong>stdin</strong> or <strong>stdout</strong>, resulting the <strong>system()</strong> function to halt and wait for it to finish...<br />
This causes PHP to reach the 30 second time limit and kill the script.</p>
<p>This script runs it in the background and you could make your commands send their output to a log file and still having full control.</p>
<p>Read the code below how to use it.</p>
<p>You can compile it by placing the code into <strong>shellproxy.c</strong> and then compile it with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> shellproxy shellproxy.c</pre></div></div>

<p>I hope this is something useful for you as it was for me.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio .h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib .h&gt;</span>
<span style="color: #339933;">#include &lt;string .h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> command<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> t<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;nShell Proxyn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;By Marius van Witzenburg &lt;http ://kitara.nl&gt;nn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;You will mostly use this program from PHP or any othern&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;webscripting language to background run programsnn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage:n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;- CLI:n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;shellproxy &quot;</span><span style="color: #339933;">&lt;</span>cmd<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>arg<span style="color: #339933;">&gt;</span><span style="color: #ff0000;">&quot;n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;shellproxy &quot;</span><span style="color: #339933;">&lt;</span>cmd<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>arg<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&gt;</span> redirect.<span style="color: #202020;">txt</span><span style="color: #ff0000;">&quot;n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;- PHP:n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;system('shellproxy &quot;</span><span style="color: #339933;">&lt;</span>cmd<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>arg<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&amp;</span><span style="color: #ff0000;">&quot;');n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;system('shellproxy &quot;</span><span style="color: #339933;">&lt;</span>cmd<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>arg<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&gt;</span> redirect.<span style="color: #202020;">txt</span><span style="color: #ff0000;">&quot;');nn&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    command<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>t <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> t <span style="color: #339933;">&lt;</span> argc<span style="color: #339933;">;</span> t<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        strcat<span style="color: #009900;">&#40;</span>command<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>t<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        strcat<span style="color: #009900;">&#40;</span>command<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    fclose<span style="color: #009900;">&#40;</span>stdin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fclose<span style="color: #009900;">&#40;</span>stdout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fclose<span style="color: #009900;">&#40;</span>stderr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    system<span style="color: #009900;">&#40;</span>command<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It would be nice if you keep my name mentioned into this code if you use it.</p>
<p>Ps. Donations are welcome... <img src='http://mariusvw.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mariusvw.com/2010/03/02/shellproxy-an-easy-tool-to-run-shell-commands-from-php-or-other-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

