<?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>Dirty Motherfucking Blog &#187; console</title>
	<atom:link href="http://dirty-motherfucker.org/blog/tag/console/feed/" rel="self" type="application/rss+xml" />
	<link>http://dirty-motherfucker.org/blog</link>
	<description>All kinds of shit</description>
	<lastBuildDate>Wed, 04 Jan 2012 15:38:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19620</generator>
		<item>
		<title>Check Write Permissions for Folder Hierachcy</title>
		<link>http://dirty-motherfucker.org/blog/2012/01/02/check-write-permissions-for-folder-hierachcy/</link>
		<comments>http://dirty-motherfucker.org/blog/2012/01/02/check-write-permissions-for-folder-hierachcy/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 15:21:54 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[find]]></category>

		<guid isPermaLink="false">http://dirty-motherfucker.org/blog/?p=344</guid>
		<description><![CDATA[While working on a bash script, I wanted to check if I could rm -rf a folder before actually attempting it and flushing the console with tons of write permission error messages. Upon failing to find what I wanted online, I constructed this beauty: find . \( -exec test -w {} \; -o \( -exec [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a bash script, I wanted to check if I could <code>rm -rf</code> a folder before actually attempting it and flushing the console with tons of write permission error messages.</p>
<p>Upon failing to find what I wanted online, I constructed this beauty:<br />
<code><br />
find . \( -exec test -w {} \; -o \( -exec echo {} \; -quit \) \) | xargs -I {} bash -c "if [ -n "{}" ]; then echo {} is not writeable\!; exit 1; fi"<br />
</code><br />
This will print the name of the item that is not writeable in addition to the non-zero return value needed when used in more complex scripts.</p>
<p>If you don&#8217;t want/need the output, you can go with the simpler version:<br />
<code><br />
find . \( -exec test -w {} \; -o \( -exec echo {} \; -quit \) \) | xargs -I {} test -z "{}"<br />
</code></p>
<p>If there is a more simple solution, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://dirty-motherfucker.org/blog/2012/01/02/check-write-permissions-for-folder-hierachcy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Self-updating Bash Script</title>
		<link>http://dirty-motherfucker.org/blog/2011/12/22/self-updating-bash-script/</link>
		<comments>http://dirty-motherfucker.org/blog/2011/12/22/self-updating-bash-script/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 11:59:58 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://dirty-motherfucker.org/blog/?p=338</guid>
		<description><![CDATA[While working on the typo3scripts project, I wanted to implement a self-updating feature into each of the scripts as that seemed most convenient for where these scripts would be used. My initial approach was OK but left me wondering. So, here is the revised approach for a bash script that has the ability to update [...]]]></description>
			<content:encoded><![CDATA[<p>While working on the <a href="http://code.google.com/p/typo3scripts/" title="typo3scripts">typo3scripts</a> project, I wanted to implement a self-updating feature into each of the scripts as that seemed most convenient for where these scripts would be used. My <a href="http://stackoverflow.com/questions/8595751/is-this-a-valid-self-update-approach-for-a-bash-script" title="Self-updating bash script at StackOverflow">initial approach</a> was OK but left me wondering.</p>
<p>So, here is the revised approach for a bash script that has the ability to update itself:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

set -o nounset
set -o errexit

SELF=$(basename $0)

# The base location from where to retrieve new versions of this script
UPDATE_BASE=http://typo3scripts.googlecode.com/svn/trunk

# Self-update
runSelfUpdate() {
  echo &quot;Performing self-update...&quot;

  # Download new version
  echo -n &quot;Downloading latest version...&quot;
  if ! wget --quiet --output-document=&quot;$0.tmp&quot; $UPDATE_BASE/$SELF ; then
    echo &quot;Failed: Error while trying to wget new version!&quot;
    echo &quot;File requested: $UPDATE_BASE/$SELF&quot;
    exit 1
  fi
  echo &quot;Done.&quot;

  # Copy over modes from old version
  OCTAL_MODE=$(stat -c '%a' $SELF)
  if ! chmod $OCTAL_MODE &quot;$0.tmp&quot; ; then
    echo &quot;Failed: Error while trying to set mode on $0.tmp.&quot;
    exit 1
  fi

  # Spawn update script
  cat &gt; updateScript.sh &lt;&lt; EOF
#!/bin/bash
# Overwrite old file with new
if mv &quot;$0.tmp&quot; &quot;$0&quot;; then
  echo &quot;Done. Update complete.&quot;
  rm \$0
else
  echo &quot;Failed!&quot;
fi
EOF

  echo -n &quot;Inserting update process...&quot;
  exec /bin/bash updateScript.sh
}

# Update check
SUM_LATEST=$(curl $UPDATE_BASE/versions 2&gt;&amp;1 | grep $SELF | awk '{print $1}')
SUM_SELF=$(md5sum $0 | awk '{print $1}')
if [[ &quot;$SUM_LATEST&quot; != &quot;$SUM_SELF&quot; ]]; then
  echo &quot;NOTE: New version available!&quot;
fi
</pre>
<p>It also includes the update check which wasn&#8217;t discussed over at StackOverflow. In case I revise the approach yet again, you&#8217;ll find the latest version over at the <a href="http://code.google.com/p/typo3scripts/" title="Typo3Scripts Project Page">typo3scripts project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dirty-motherfucker.org/blog/2011/12/22/self-updating-bash-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Increased Screen-Space for Ubuntu Server VM</title>
		<link>http://dirty-motherfucker.org/blog/2010/10/13/increased-screen-space-for-ubuntu-server-vm/</link>
		<comments>http://dirty-motherfucker.org/blog/2010/10/13/increased-screen-space-for-ubuntu-server-vm/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 09:49:37 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.dirty-motherfucker.org/blog/?p=320</guid>
		<description><![CDATA[I often run Ubuntu server installations in VirtualBox. Sadly, this only provides you with the default console window. So most of the time I would additionally connect with Putty into the same VM, so that I can make use of a larger console. But recently it pissed me off so badly that I went hunting [...]]]></description>
			<content:encoded><![CDATA[<p>I often run Ubuntu server installations in VirtualBox. Sadly, this only provides you with the default console window. So most of the time I would additionally connect with Putty into the same VM, so that I can make use of a larger console. But recently it pissed me off so badly that I went hunting for a solution. And I found it in <a href="http://joeamined.wordpress.com/2008/02/25/enabling-high-resolution-console-in-ubuntu/">this article</a>. It&#8217;s not quite up speed with the current environment, so I&#8217;ll duplicate the information here and update it as well.</p>
<p>So first thing we want to do is remove the vesa framebuffer module from the modprobe blacklist.</p>
<pre class="brush: plain; title: ; notranslate">sudo editor /etc/modprobe.d/blacklist-framebuffer</pre>
<p>Comment out or delete the following line:</p>
<pre class="brush: plain; title: ; notranslate">blacklist vesafb</pre>
<p>Now to enable the needed modules:</p>
<pre class="brush: plain; title: ; notranslate">sudo editor /etc/initramfs-tools/modules</pre>
<p>And add the following lines at the end:</p>
<pre class="brush: plain; title: ; notranslate">fbcon
vesafb</pre>
<p>Finally, update your initramfs images:</p>
<pre class="brush: plain; title: ; notranslate">sudo update-initramfs -u</pre>
<p>Now, we need to make Grub pass the required parameters to the kernel to enable the high-res console.<br />
In case of Ubuntu 8.04 (and 8.10 I guess) or any pre-Grub2 version:</p>
<pre class="brush: plain; title: ; notranslate">sudo editor /boot/grub/menu.lst</pre>
<p>For Grub2 installations:</p>
<pre class="brush: plain; title: ; notranslate">sudo editor /etc/default/grub</pre>
<p>There will be a line like this:</p>
<pre class="brush: plain; title: ; notranslate">GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash&quot;</pre>
<p>You&#8217;re gonna want to add the vga parameter to that:</p>
<pre class="brush: plain; title: ; notranslate">GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash vga=791&quot;</pre>
<p>Or as the original article suggests (and what I prefer as well):</p>
<pre class="brush: plain; title: ; notranslate">GRUB_CMDLINE_LINUX_DEFAULT=&quot;verbose vga=791&quot;</pre>
<p>But that only changes the amount of information you get during boot time.<br />
The number that is passed as an argument with vga signals the desired resolution and color depth. 791 is 1024&#215;768 with 64K colors. A full list can be found <a href="http://www.mjmwired.net/kernel/Documentation/fb/vesafb.txt">here</a>.<br />
Now, for Grub2 installations you&#8217;ll want to update Grub:</p>
<pre class="brush: plain; title: ; notranslate">sudo update-grub2</pre>
<p>And then, reboot!</p>
<pre class="brush: plain; title: ; notranslate">sudo reboot now</pre>
]]></content:encoded>
			<wfw:commentRss>http://dirty-motherfucker.org/blog/2010/10/13/increased-screen-space-for-ubuntu-server-vm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run .bat file with a set of parameters</title>
		<link>http://dirty-motherfucker.org/blog/2009/11/28/run-bat-file-with-a-set-of-parameters/</link>
		<comments>http://dirty-motherfucker.org/blog/2009/11/28/run-bat-file-with-a-set-of-parameters/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 00:39:18 +0000</pubDate>
		<dc:creator>gencha</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[.bat]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[console]]></category>

		<guid isPermaLink="false">http://www.dirty-motherfucker.org/blog/?p=287</guid>
		<description><![CDATA[I am currently working on a project of larger scale than what I am usually working on. During this project I wrote several small tools which I personally feel are somewhat interesting. I&#8217;ll try to write up a few posts about some solutions I came up with to kinda special problems. This is the first [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project of larger scale than what I am usually working on. During this project I wrote several small tools which I personally feel are somewhat interesting.<br />
I&#8217;ll try to write up a few posts about some solutions I came up with to kinda special problems.<br />
This is the first one and I already feel the topic is not capturing the essence of what this tool does.</p>
<p>In this project we have a Windows domain of about 100 machines which are running our software are mainly used to display &#8220;stuff&#8221; (let&#8217;s not go into details).<br />
When I arrived on site where we deployed our product I found that some technicians where using .bat files to deploy files to machines in the domain. After deploying their files they would restart the machine remotely through Windows remote desktop feature. They would repeat that process for every machine in the domain manually until the desired group was up-to-date.<br />
Needless to say, for a programmer, this seemed unnecessarily cumbersome. This was when I wrote the first helpful tool.</p>
<p>The tool will read a .xml file which contains target IP addresses (or machine names if DNS is available) and will use them as a parameter to a supplied batch file. Alternatively it would use a list of targets supplied via the command line. Thus enabling you to run a .bat file for a large set of targets.<br />
Let&#8217;s have a look at the source:</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Xml;
using System.Diagnostics;

namespace BatchProcessor {
  class Program {

    private const   String      APPLICATION_NAME    = &quot;Batch Processor&quot;;
    private const   String      APPLICATION_VERSION = &quot;0.1&quot;;

    private static ConsoleColor defaultColor        = ConsoleColor.Gray;

    static void Main( string[] args ) {

      Console.WindowWidth = 160;
      Console.Title = String.Format( &quot;{0} {1}&quot;, APPLICATION_NAME, APPLICATION_VERSION );

      Console.ForegroundColor = ConsoleColor.Cyan;
      Console.WriteLine( String.Format( &quot;{0} {1}&quot;, APPLICATION_NAME, APPLICATION_VERSION ) );
      Console.ForegroundColor = ConsoleColor.DarkCyan;
      Console.WriteLine( &quot;CPP Studios Event GmbH 2009&quot; );
      Console.ForegroundColor = defaultColor;

      string        batchFile   = String.Empty;
      string        targetsFile = String.Empty;
      List&lt;string&gt;  targets     = new List&lt;string&gt;();

      if( args.Length &lt; 2 ) {
        errorExit( &quot;Incorrect number of arguments&quot; );
        return;
      }

      batchFile   = args[ 0 ];
      targetsFile = args[ 1 ];

      // Check if targetsFile is actually a file
      FileInfo targetsFileInfo = new FileInfo( targetsFile );
      if( !targetsFileInfo.Exists ) {
        for( int targetIndex = 1; targetIndex &lt; args.Length; ++targetIndex ) {
          targets.Add( args[ targetIndex ] );
        }

      } else {
        XmlDocument targetFile = new XmlDocument();
        try {
          Console.WriteLine( String.Format( &quot;Reading targets from {0}...&quot;, targetsFile ) );
          targetFile.Load( targetsFile );

          XmlNodeList targetNodes = targetFile.SelectNodes( &quot;/targets/target&quot; );
          foreach( XmlNode targetNode in targetNodes ) {
            targets.Add( targetNode.Attributes[ &quot;ip&quot; ].InnerText );
          }

        } catch( Exception ex ) {
          Console.ForegroundColor = ConsoleColor.Red;
          Console.WriteLine( &quot;Error while reading targets: &quot; + ex.Message );
          Console.ForegroundColor = defaultColor;
        }
      }
      Console.WriteLine( String.Format( &quot;Got {0} targets&quot;, targets.Count ) );

      foreach( String target in targets ) {
        string commandLine = String.Format( &quot;{0} {1}&quot;, batchFile, target );
        Console.ForegroundColor = ConsoleColor.DarkGreen;
        Console.WriteLine( String.Format( &quot;Executing '{0}'...&quot;, commandLine ) );
        Console.ForegroundColor = defaultColor;

        ProcessStartInfo  p     = new ProcessStartInfo( batchFile );
        Process           proc  = new Process();

        p.Arguments               = target;
        p.RedirectStandardOutput  = true;
        p.UseShellExecute         = false;
        proc.StartInfo            = p;

        proc.Start();
        StreamReader outputReader = proc.StandardOutput;

        proc.WaitForExit();
        Console.Write( outputReader.ReadToEnd() );

        Console.ForegroundColor = ConsoleColor.DarkGreen;
        Console.WriteLine( String.Format( &quot;Finished processing '{0}'.&quot;, commandLine ) );
        Console.ForegroundColor = defaultColor;
      }

      Console.ForegroundColor = ConsoleColor.Magenta;
      Console.WriteLine( &quot;Operation completed.&quot; );
      Console.ForegroundColor = defaultColor;

    }

    private static void errorExit( String errorMessage ) {
      Console.ForegroundColor = ConsoleColor.Red;
      Console.WriteLine( errorMessage );
      Console.ForegroundColor = defaultColor;
      Thread.Sleep( 5000 );
    }

  }
}
</pre>
<p>Pretty much a straight forward implementation of what I explained above.<br />
What amazed me most about the tool was the simplicity and how much can be achieved by the approach. Everyone who is capable of writing a .bat file could plug it right into the system and apply the command set to our pre-defined groups. I like to think that it turned out to be a very simple, yet versatile tool.</p>
<p>Another thing to notice is the console redirection used here. It&#8217;s pretty much what you will find if you google for &#8220;c# redirect console output&#8221; in a few seconds. Soon I noticed that it&#8217;s a very shitty way to redirect console output and leaves a lot to wish for. I will cover that topic in more detail in an upcoming post.</p>
]]></content:encoded>
			<wfw:commentRss>http://dirty-motherfucker.org/blog/2009/11/28/run-bat-file-with-a-set-of-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

