<?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>Solid State Raam &#187; Linux</title>
	<atom:link href="http://solidstateraam.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://solidstateraam.com</link>
	<description>Explorations (and exploitations) of the digital world by one of its many netizens.</description>
	<lastBuildDate>Thu, 13 May 2010 19:24:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unix/Linux: Finding and Killing Processes by User</title>
		<link>http://solidstateraam.com/unixlinux-finding-and-killing-processes-by-user/</link>
		<comments>http://solidstateraam.com/unixlinux-finding-and-killing-processes-by-user/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 05:00:34 +0000</pubDate>
		<dc:creator>Raam</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://solidstateraam.com/?p=385</guid>
		<description><![CDATA[If you've ever run <code>ps aux &#124; grep user</code> to list processes and hunt for process IDs, you'll be happy to know there is a simpler alternative. Both finding and killing processes owned by a particular user is made simple using the handy <code>pgrep</code> and <code>pkill</code> utilities. ]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever run <code>ps aux | grep user</code> to list processes and hunt for process IDs, you&#8217;ll be happy to know there is a simpler alternative. Both finding and killing processes owned by a particular user is made simple using the handy <code>pgrep</code> and <code>pkill</code> utilities. </p>
<p><strong>Listing Processes with pgrep</strong></p>
<p>Listing all the processes owned by the user <code>raam</code> can be done like this (the <code>-l</code> switch causes the output to include the process name):</p>
<pre class="brush: bash;">
$ pgrep -l -u raam
9614 screen
9628 bash
9644 irssi
16165 bash
16297 rtorrent
19462 ssh
19515 bash
19526 ssh
20964 sshd
</pre>
<p>You can also filter the list of results by appending a full (or partial) process name to the command:</p>
<pre class="brush: bash;">
$ pgrep -l -u raam bash
9628 bash
16165 bash
19515 bash
</pre>
<p><strong>Killing Processes with pkill</strong></p>
<p>The <code>pkill</code> command does basically the same thing as <code>pgrep</code>, except it kills the processes instead of listing them. This is useful if you have a user with several dead processes, or if you were deleting a user and you wanted to kill any running processes first.</p>
<p>Killing all the processes owned by the user <code>raam</code> looks like this:</p>
<pre class="brush: bash;">
$ pkill -u raam
</pre>
<p>And once again, if you only wanted to kill all the bash processes owned by <code>raam</code>, you would append the process name to the command:</p>
<pre class="brush: bash;">
$ pkill -u raam bash
</pre>
<p>As always, check the man pages for <code>pgrep</code> and <code>pkill</code> for more information and switch options.</p>
]]></content:encoded>
			<wfw:commentRss>http://solidstateraam.com/unixlinux-finding-and-killing-processes-by-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MAC Address Validation Regex with egrep</title>
		<link>http://solidstateraam.com/mac-address-validation-regex-with-egrep/</link>
		<comments>http://solidstateraam.com/mac-address-validation-regex-with-egrep/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 00:45:08 +0000</pubDate>
		<dc:creator>Raam</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://solidstateraam.com/?p=334</guid>
		<description><![CDATA[I needed an easy way to validate a MAC address in a bash script that generated a unique hostname based on the MAC address of the system. Read about how I solved the problem using a regular expression and egrep.]]></description>
			<content:encoded><![CDATA[<p>I needed an easy way to validate a MAC address in a bash script that generated a unique hostname based on the MAC address of the system. This gem did the trick:</p>
<pre class="brush: bash;">
echo &quot;00:11:24:3e:a5:78&quot; | egrep &quot;^([0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}$&quot;
</pre>
<p>In the event that there was a problem getting the MAC address (e.g., faulty NIC or unstable device driver), I generate a random hostname instead of basing the hostname generation on the MAC. Here&#8217;s how I validated the MAC in the script:</p>
<pre class="brush: bash;">
if [ `echo $ACTIVE_INTERFACE_MAC | egrep &quot;^([0-9a-fA-F]{2}\:){5}[0-9a-fA-F]{2}$&quot;` ]; then
	# generate unique hostname based on MAC
else
	# generate random-character hostname
fi
</pre>
]]></content:encoded>
			<wfw:commentRss>http://solidstateraam.com/mac-address-validation-regex-with-egrep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Script to Install &amp; Configure ifplugd on Debian</title>
		<link>http://solidstateraam.com/a-script-to-install-configure-ifplugd-on-debian/</link>
		<comments>http://solidstateraam.com/a-script-to-install-configure-ifplugd-on-debian/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 05:00:56 +0000</pubDate>
		<dc:creator>Raam</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>

		<guid isPermaLink="false">http://solidstateraam.com/?p=148</guid>
		<description><![CDATA[The default configuration on some older Linux systems is to only send a DHCP request while booting up. This means if the network cable gets unplugged, or if the router is powered off, the system may lose its IP configuration. To restore the network connection, the system may need to be manually rebooted or have [...]]]></description>
			<content:encoded><![CDATA[<p>The default configuration on some older Linux systems is to only send a DHCP request while booting up. This means if the network cable gets unplugged, or if the router is powered off, the system may lose its IP configuration. To restore the network connection, the system may need to be manually rebooted or have someone at the local console run the <code>dhclient</code> command to request a DHCP lease. </p>
<p>For systems that are only accessed remotely via SSH, such a scenario can be painful. What is needed is a daemon that watches the link status of the Ethernet jack and reconfigures the network (or sends out another DHCP request) when it detects a cable is plugged in (or the power to the router is restored).</p>
<p><a href="http://0pointer.de/lennart/projects/ifplugd/#overview">ifplugd</a> does exactly that:</p>
<blockquote><p>ifplugd is a Linux daemon which will automatically configure your ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled.</p></blockquote>
<p>On a Debian system, installing and configuring ifplugd is relatively simple using <code>apt-get install ifplugd</code>. Once its been installed, it needs to be configured by editing <code>/etc/default/ifplugd</code>. The most basic configuration is to simply set <code>INTERFACES="auto"</code> and <code>HOTPLUG_INTERFACES="all"</code>. This configuration tells ifplugd to watch all network interfaces for a new link status and automatically reconfigure them using the Debian network configuration defined in <code>/etc/network/interfaces</code>.</p>
<p>I recently needed to automate the install and configuration of ifplugd on many remote Linux systems, so I wrote this simple script.  </p>
<p>Download: <a href="http://solidstateraam.com/wp-content/uploads/2009/06/install-ifplugd.tar.gz">install-ifplugd.tar.gz</a></p>
<pre class="brush: bash;">
#!/bin/sh

#########################################
# Author: Raam Dev
#
# This script installs ifplugd and configures
# it to automatically attempt to restore any
# lost connections.
#
# Must be run as root!
#########################################

# Check if we're running this as root
if [ $EUID -ne 0 ]; then
   echo &quot;This script must be run as root&quot; 1&gt;&amp;2
   exit 1
fi

# Files used when configuring ifplugd
OUTFILE=/tmp/outfile.$$
CONFIG_FILE=/etc/default/ifplugd

# Update package list and install ifplugd, assuming yes to any questions asked
# (to insure the script runs without requiring manual intervention)
apt-get update --assume-yes ; apt-get install --assume-yes ifplugd

# Configure ifplugd to watch all interfaces and automatically attempt configuration
sed 's/INTERFACES=\&quot;\&quot;/INTERFACES=\&quot;auto\&quot;/g' &lt; $CONFIG_FILE &gt; $OUTFILE
mv $OUTFILE $CONFIG_FILE

sed 's/HOTPLUG_INTERFACES=\&quot;auto\&quot;/HOTPLUG_INTERFACES=\&quot;all\&quot;/g' &lt; $CONFIG_FILE &gt; $OUTFILE
mv $OUTFILE $CONFIG_FILE
</pre>
<p>If you&#8217;re interested in doing more with ifplugd, check out <a href="http://www.linux.com/archive/articles/114008">this article</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://solidstateraam.com/a-script-to-install-configure-ifplugd-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving Files as root From Inside VIM</title>
		<link>http://solidstateraam.com/saving-files-as-root-from-inside-vim/</link>
		<comments>http://solidstateraam.com/saving-files-as-root-from-inside-vim/#comments</comments>
		<pubDate>Sat, 09 May 2009 02:53:36 +0000</pubDate>
		<dc:creator>Raam</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[VIM]]></category>

		<guid isPermaLink="false">http://solidstateraam.com/?p=187</guid>
		<description><![CDATA[Oftentimes I will be editing a Linux configuration file using vim only to discover that I cannot save it because the file requires root permission to write to it. See how I solved this problem using the linux <code>tee</code> utility.]]></description>
			<content:encoded><![CDATA[<p>Oftentimes I will be editing a Linux configuration file using vim only to discover that I cannot save it because the file requires root permission to write to it. This ends up looking something like this:</p>
<pre class="brush: bash;">
vi /path/to/some/file.conf
[make some edits]
:w
VIM Message: E45: 'readonly' option is set (add ! to override)
:q!
$ sudo vi /path/to/some/file.conf
[make all my edits AGAIN]
:w
</pre>
<p>I have gone through this process <em>so many times</em> that I knew there must be an easy fix for it. (I know about <code>sudo !!</code> for running the previous command, but I only recently started developing the habit of using it.) After forgetting to use sudo while editing a configuration file yet again this morning, I finally decided to search Google and find a solution. Here it is:</p>
<pre class="brush: bash;">
vi /path/to/some/file.conf
[make some edits]
:w
VIM Message: E45: 'readonly' option is set (add ! to override)
:w !sudo tee %
</pre>
<p>The <code>:w !sudo tee %</code> command tells VIM to write the file (<code>w</code>) but run the sudo command first (<code>!sudo</code>) and read the writing of the file from standard input to standard output (<code>tee</code>) using the same filename as the one we&#8217;re editing (<code>%</code>).</p>
<p>After saving the file as root, you&#8217;ll get this message: &#8220;W12: Warning: File &#8220;/private/etc/smb.conf&#8221; has changed and the buffer was changed in Vim as well&#8221;. You&#8217;ll be given the option to reload it, but since you were already looking at the new version it doesn&#8217;t much matter which option you choose (OK or Reload).</p>
<p>And last but not least, if you don&#8217;t want to remember the syntax for this command, you can map the command in your ~/.vimrc file:</p>
<pre class="brush: bash;">
cmap w!! w !sudo tee % &gt;/dev/null
</pre>
<p>Now, if you forget to edit a file with sudo, you can simply type <code>:w!!</code> to fix the problem!</p>
]]></content:encoded>
			<wfw:commentRss>http://solidstateraam.com/saving-files-as-root-from-inside-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Forcing fsck to Run on the Next Reboot</title>
		<link>http://solidstateraam.com/forcing-fsck-to-run-on-the-next-reboot/</link>
		<comments>http://solidstateraam.com/forcing-fsck-to-run-on-the-next-reboot/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 04:38:29 +0000</pubDate>
		<dc:creator>Raam</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://solidstateraam.com/?p=134</guid>
		<description><![CDATA[The system utility fsck is a tool for checking the consistency of a file system in Unix/Linux. Forcing <code>fsck</code> to run on next reboot is very simple.]]></description>
			<content:encoded><![CDATA[<p>If you need to make sure fsck runs on the next reboot, here&#8217;s a really simple way to do it:</p>
<pre class="brush: bash;">
$ sudo touch /forcefsck
</pre>
<p>Alternatively (and depending on your version of Linux) you may also be able to pass an option to the shutdown command:</p>
<pre class="brush: bash;">
$ shutdown -rF now
</pre>
]]></content:encoded>
			<wfw:commentRss>http://solidstateraam.com/forcing-fsck-to-run-on-the-next-reboot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring Static DNS with DHCP on Debian/Ubuntu</title>
		<link>http://solidstateraam.com/configuring-static-dns-with-dhcp-on-debianubuntu/</link>
		<comments>http://solidstateraam.com/configuring-static-dns-with-dhcp-on-debianubuntu/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 04:53:22 +0000</pubDate>
		<dc:creator>Raam</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://solidstateraam.com/?p=74</guid>
		<description><![CDATA[Dynamic Host Configuration Protocol (DHCP) is a commonly used method of obtaining IP and DNS information automatically from the network. In some cases, you may wish to statically define the DNS servers instead of using the ones provided by the DHCP server. For example if your ISP commonly experiences DNS outages, you might want to [...]]]></description>
			<content:encoded><![CDATA[<p>Dynamic Host Configuration Protocol (<a title="Wikipedia entry on DHCP" href="http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol">DHCP</a>) is a commonly used method of obtaining IP and DNS information automatically from the network. In some cases, you may wish to statically define the DNS servers instead of using the ones provided by the DHCP server. For example if your ISP commonly experiences DNS outages, you might want to use the DNS servers provided by <a title="OpenDNS" href="http://opendns.com">OpenDNS</a> instead of the ones provided by your ISP.</p>
<p>When using a static IP configuration on Linux, you normally add the DNS servers to the <code>/etc/resolv.conf</code>. However, if you try to add a DNS server to <code>/etc/resolv.conf</code> under a DHCP configuration, you&#8217;ll notice that your static entry disappears as soon as the DHCP client runs (usually on boot). To prevent this, you need to tell the DHCP client to prepend the static DNS server(s) to <code>/etc/resolv.conf</code> before adding the ones provided from the DHCP server (if any).</p>
<p>The configuration file you&#8217;ll need to edit is the same on both Debian and Ubuntu, however depending on your setup the location of the file may vary. Here are the two common places I&#8217;ve found the file:</p>
<p><strong>Debian:</strong> <code>/etc/dhclient.conf</code><br />
<strong>Ubuntu:</strong> <code>/etc/dhcp3/dhclient.conf</code></p>
<p>Open the file in your favorite editor and add one of two lines at the top, separating multiple DNS servers with a comma and ending the entry with a semi-colon:</p>
<p>If you simply want to add static DNS servers to be used in addition to the ones provided by DHCP, use a prepend entry:</p>
<pre class="brush: bash;">prepend domain-name-servers 208.67.222.222, 208.67.220.220;</pre>
<p>If you want to override the DNS servers provided by DHCP entirely and force the system to use the ones you provide, use the supersede entry:</p>
<pre class="brush: bash;">supersede domain-name-servers 208.67.222.222, 208.67.220.220;</pre>
<p>Before these static DNS servers will to be appended to your <code>/etc/resolv.conf</code> file, you&#8217;ll need to re-run the DHCP client. The easiest way to do this is by running <code>/etc/init.d/networking restart</code> (sudo required) or you can try running the <code>dhclient</code> command. </p>
<p>After re-running the DHCP client, check your <code>/etc/resolv.conf</code> file to confirm the static DNS servers have been added.</p>
]]></content:encoded>
			<wfw:commentRss>http://solidstateraam.com/configuring-static-dns-with-dhcp-on-debianubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
