<?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>Mike Zupan&#039;s Random Blog</title>
	<atom:link href="http://zcentric.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zcentric.com</link>
	<description>A blog about linux, programming and more</description>
	<lastBuildDate>Thu, 13 Oct 2011 14:56:16 +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>Postfix ignore catchall relayhost</title>
		<link>http://zcentric.com/2011/10/13/postfix-ignore-catchall-relayhost/</link>
		<comments>http://zcentric.com/2011/10/13/postfix-ignore-catchall-relayhost/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 14:53:28 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[relayhost]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=346</guid>
		<description><![CDATA[Postfix has an option where you can setup a relayhost to send all mail to another mail server. It looks something like relayhost = [mail.domain.com]:25 So that will send all mail being sent out from the server to mail.domain.com on port 25. So what happens if you want to send mail that is sent to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F10%2F13%2Fpostfix-ignore-catchall-relayhost%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F10%2F13%2Fpostfix-ignore-catchall-relayhost%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Postfix has an option where you can setup a relayhost to send all mail to another mail server. It looks something like</p>
<p><code>relayhost = [mail.domain.com]:25</code></p>
<p>So that will send all mail being sent out from the server to mail.domain.com on port 25. So what happens if you want to send mail that is sent to company.com out that server and not through another relay. You would do the following in main.cf</p>
<p><code>transport_maps = hash:/etc/postfix/transport</code></p>
<p>Then your /etc/postfix/transport would look something like</p>
<pre><code>company.com :
* smtp:[mail.domain.com]:25</code></pre>
<p>Then you want to run</p>
<p><code>postmap /etc/postfix/transport</code></p>
<p>Then reload postfix</p>
<p><code>service postfix reload</code></p>
<p>Now all mail for company.com will send out that server while all other mail will go through mail.domain.com:25</p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/10/13/postfix-ignore-catchall-relayhost/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ps aux with line wrap</title>
		<link>http://zcentric.com/2011/08/22/ps-aux-with-line-wrap/</link>
		<comments>http://zcentric.com/2011/08/22/ps-aux-with-line-wrap/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 09:55:51 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Sys Admin]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=273</guid>
		<description><![CDATA[File this under you learn something new every day. Ever do a ps aux only to get something like this to happen? xymon 26931 0.0 0.0 38944 1396 ? S 05:44 0:00 sh -c vmstat 300 2 1>/usr/lib64/xymon/client/tmp/hob So the output of ps aux gets cut off when it hits the end of your terminal. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F08%2F22%2Fps-aux-with-line-wrap%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F08%2F22%2Fps-aux-with-line-wrap%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>File this under you learn something new every day.</p>
<p>Ever do a <strong>ps aux</strong> only to get something like this to happen?</p>
<p><code>xymon    26931  0.0  0.0  38944  1396 ?        S    05:44   0:00 sh -c vmstat 300 2 1>/usr/lib64/xymon/client/tmp/hob</code></p>
<p>So the output of ps aux gets cut off when it hits the end of your terminal. And you have to expand your width a lot to see it. It always bothered me till I decided to read the man page.</p>
<p>Now I learned you can do</p>
<p><code>ps aux --width 1000</code></p>
<p>That will line wrap your output but cut the output at 1000 characters. You can also pass w&#8217;s into the command like</p>
<p><code>ps auxww</code></p>
<p>That will ignore your terminals width settings</p>
<p>So now we can add the following in our .bashrc or for system wide /etc/profile so we never have to remember to add a ww or &#8211;width again</p>
<p><code>alias ps='ps ww'</code></p>
<p>So that alias means you can type <strong>ps aux</strong> and it will be like your typed <strong>ps auxww</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/08/22/ps-aux-with-line-wrap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fabric Shell</title>
		<link>http://zcentric.com/2011/06/27/fabric-shell/</link>
		<comments>http://zcentric.com/2011/06/27/fabric-shell/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 21:16:13 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[fabric]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=267</guid>
		<description><![CDATA[I recently wrote a quick little fabric function to create a fabric shell. This works with a stock fabric install, you just might have to change where you import it from. It is at my Github page below. https://github.com/mzupan/fabric_shell If you place shell.py in the same directory as fabfile.py you can use it like from [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F06%2F27%2Ffabric-shell%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F06%2F27%2Ffabric-shell%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently wrote a quick little fabric function to create a fabric shell. This works with a stock fabric install, you just might have to change where you import it from. It is at my Github page below.</p>
<p><a href="https://github.com/mzupan/fabric_shell">https://github.com/mzupan/fabric_shell</a></p>
<p>If you place shell.py in the same directory as fabfile.py you can use it like</p>
<pre><code>from fabric.api import *
from fabric.decorators import hosts

import shell

env.hosts = [
    'host1.domain.com',
    'host2.domain.com'
]

@hosts('')
def cmd():
    shell.shell()</code></pre>
<p>Then you can use like like</p>
<pre><code>$ fab cmd
[] Executing task 'cmd'
fabric::> id
[host1.domain.com] run: id
[host1.domain.com] out: uid=1020(mzupan) gid=1020(mzupan) groups=1020(mzupan)
[host1.domain.com] out:
[host2.domain.com] run: id
[host2.domain.com] out: uid=1020(mzupan) gid=1020(mzupan) groups=1020(mzupan)
[host2.domain.com] out:
fabric::> .sudo id
[host1.domain.com] sudo:  id
[host1.domain.com] out: uid=0(root) gid=0(root) groups=0(root)
[host1.domain.com] out:
[host2.domain.com] sudo:  id
[host2.domain.com] out: uid=0(root) gid=0(root) groups=0(root)
[host2.domain.com] out:
fabric::> </code></pre>
<p>Right now any command that is issued in the fabric shell gets run on all hosts in env.hosts and if you add .sudo in front of the command it will run them as root. </p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/06/27/fabric-shell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fun with Django ManyToMany Fields</title>
		<link>http://zcentric.com/2011/06/21/fun-with-django-manytomany-fields/</link>
		<comments>http://zcentric.com/2011/06/21/fun-with-django-manytomany-fields/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 06:11:00 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[manytomany]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=261</guid>
		<description><![CDATA[This is just another reason I find Django so easy. For example.. Say you are making a monitoring application. Now you have a bunch of servers and you have certain groups of servers. A server can belong in more then one group also. So that is pretty easy and all with Django. Now in your [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F06%2F21%2Ffun-with-django-manytomany-fields%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F06%2F21%2Ffun-with-django-manytomany-fields%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is just another reason I find Django so easy.</p>
<p>For example.. Say you are making a monitoring application. Now you have a bunch of servers and you have certain groups of servers. A server can belong in more then one group also. So that is pretty easy and all with Django.</p>
<p>Now in your template you have a few pages. One page that displays the group information like all the servers in the group and another that displays the server information and will list all the groups that server is in. So below is my basic model layout</p>
<pre><code>class Group(models.Model):
    parent = models.ForeignKey("Group", null=True, blank=True)
    user = models.ForeignKey(User)

    name = models.CharField(max_length=100)
    about = models.TextField(blank=True, null=True)

    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.name

class Server(models.Model):
    hostname = models.CharField(max_length=300, db_index=True)
    about = models.TextField(blank=True, null=True)

    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    groups = models.ManyToManyField(Group)

    def __unicode__(self):
        return self.hostname</code></pre>
<p>So to get all the groups my server is a member of is pretty easy.</p>
<pre><code>s = Server.objects.get(id=1)
s.groups.all()</code></pre>
<p>Now to get all the servers in a group is also easy</p>
<pre><code>g = Group.objects.get(id=1)
g.server_set.all()</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/06/21/fun-with-django-manytomany-fields/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crontab with a random sleep</title>
		<link>http://zcentric.com/2011/06/03/crontab-with-a-random-sleep/</link>
		<comments>http://zcentric.com/2011/06/03/crontab-with-a-random-sleep/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 15:51:18 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[sleep]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=257</guid>
		<description><![CDATA[Recently ran into this problem. We had a crontab entry that looked something like this 0 0 * * * /usr/bin/sleep $((RANDOM\%90)); cmdHere What that attempted was to run a command a random amount of seconds once midnight hit. Now running the command on console causes it to error out $  /usr/bin/sleep $((RANDOM\%90)) -bash: RANDOM\%90: [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F06%2F03%2Fcrontab-with-a-random-sleep%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F06%2F03%2Fcrontab-with-a-random-sleep%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently ran into this problem. We had a crontab entry that looked something like this</p>
<p><code>0 0 * * * /usr/bin/sleep $((RANDOM\%90)); cmdHere</code></p>
<p>What that attempted was to run a command a random amount of seconds once midnight hit. Now running the command on console causes it to error out</p>
<pre><code>$  /usr/bin/sleep $((RANDOM\%90))
-bash: RANDOM\%90: syntax error: invalid arithmetic operator (error token is "\%90")</code></pre>
<p>So what you might be saying is well the \ is messing it up so remove it. Well the problem is % is a reserved character in crontab land. It pretty much means ignore everything after it so you escape it. But its not working as expected. If you remove the \ from the shell command it works just fine. </p>
<p>So the real answer here was use <strong>expr</strong>. Once that was in all the crontab errors went away</p>
<p><code>0 0 * * * /bin/sleep `/usr/bin/expr $RANDOM \% 90`; cmdHere</code></p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/06/03/crontab-with-a-random-sleep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Atomic Symlink Changes</title>
		<link>http://zcentric.com/2011/04/01/atomic-symlink-changes/</link>
		<comments>http://zcentric.com/2011/04/01/atomic-symlink-changes/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 17:11:30 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Sys Admin]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=247</guid>
		<description><![CDATA[A common deploy strategy for a lot of web sites is as follows v1.0.10 v1.0.11 v1.1.0 current -> v1.1.0 So in this directory we have three directories and one symlink. The directories contain our web application and are tagged with the source control version they were tagged with by the developers. Now its a common [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F04%2F01%2Fatomic-symlink-changes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F04%2F01%2Fatomic-symlink-changes%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A common deploy strategy for a lot of web sites is as follows</p>
<pre><code>v1.0.10
v1.0.11
v1.1.0
current -> v1.1.0</code></pre>
<p>So in this directory we have three directories and one symlink. The directories contain our web application and are tagged with the source control version they were tagged with by the developers. Now its a common practice when deploying a new version to upload the new release which will be v1.1.1 and then just change the symlink to point to the new location. That really isn&#8217;t a great idea. </p>
<p>Sure it will work for 99.9% of your traffic but if you have a busy website it could really effect users as your do the upgrade. You are probably saying well I&#8217;m forcing the new symlink with the following command</p>
<p><code>ln -snf v1.1.1 current</code></p>
<p>Did you ever look at the system calls using the -f flag for ln does? If not lets take a look</p>
<pre><code># strace ln -snf v1.1.1 current 2>&#038;1 | grep link
symlink("v1.1.1", "current")            = -1 EEXIST (File exists)
unlink("current")                       = 0
symlink("v1.1.1", "current")            = 0</code></pre>
<p>So you can see it first tries to create the link and finds the symlink is there so it unlinks curent and makes the new symlink. The man page even says this is the case!</p>
<p><code> -f    If the target file already exists, then unlink it so that the link may occur.  (The -f option overrides any previous -i options.)</code></p>
<p>So how do we make this more atomic so that our users do not even notice and everyone is happy? Well its very simple. </p>
<p><code>ln -s v1.1.1 current.new &#038;&#038; mv -Tf current.new current</code></p>
<p>That will do an atomic update.  If you want to learn more about the -T flag you can find it <a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#Target-directory">here</a></p>
<p>It might not be 100% atomic but it&#8217;s really the best I can get right now. POSIX says its atomic so right now I&#8217;ll trust it. </p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/04/01/atomic-symlink-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tav&#8217;s Fabric Fork Quick Start</title>
		<link>http://zcentric.com/2011/03/07/tavs-fabric-fork-quick-start/</link>
		<comments>http://zcentric.com/2011/03/07/tavs-fabric-fork-quick-start/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 21:55:12 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[fabric]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=238</guid>
		<description><![CDATA[I&#8217;ve been a big fan of the fabric project for a long time now. It has made my life very easy in the past and gets better with each new release. Well a few weeks ago I got introduced to a fork of the project by Tav. It provides many new feature additions to fabric [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F03%2F07%2Ftavs-fabric-fork-quick-start%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F03%2F07%2Ftavs-fabric-fork-quick-start%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve been a big fan of the <a href="http://fabfile.org">fabric</a> project for a long time now. It has made my life very easy in the past and gets better with each new release. Well a few weeks ago I got introduced to a fork of the project by <a href="http://tav.espians.com/fabric-python-with-cleaner-api-and-parallel-deployment-support.html" target="_blank">Tav</a>. It provides many new feature additions to fabric and makes fabric a little bit better. So the best way to get it started is via the following</p>
<pre><code>git clone git://github.com/tav/pylibs.git
cd pylibs
python setup.py
export PYTHONPATH=$PYTHONPATH:`pwd`</code></pre>
<p>Once installed, you have to create a fab app</p>
<p><code>vi /usr/bin/fab</code></p>
<p>Then you want to add the following contents to it</p>
<pre><code>#!/usr/bin/env python

from fabric.main import main
main()</code></pre>
<p>Then you want to give it the correct permissions</p>
<p><code>chmod +x /usr/bin/fab</code></p>
<p>Now create a directory and place a<strong> fabfile.py</strong> file in it.</p>
<p>Now create a config.yml file and use the following as a simple template</p>
<pre><code>default:
  shell: /bin/bash -l -c

servers:
  directory: /dir
  hosts:
    - host1.domain.com
    - host2.domain.com</code></pre>
<p>Then your fab file could look something like</p>
<pre><code>from fabric.api import *

env.config_file = 'config.yml'
env.user = 'mzupan'

@task('servers')
def command():
    env().multirun('uname -a')</code></pre>
<p>Normally fabric runs in serial, but Tav&#8217;s port adds a multirun() function that runs the commands in parallel. BONUS!</p>
<p>Feel free to play around with it and check out his blog post on it to get more commands.</p>
<p><a href="http://tav.espians.com/fabric-python-with-cleaner-api-and-parallel-deployment-support.html">http://tav.espians.com/fabric-python-with-cleaner-api-and-parallel-deployment-support.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/03/07/tavs-fabric-fork-quick-start/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Senior Linux Admin Interview Question #2</title>
		<link>http://zcentric.com/2011/01/14/senior-linux-admin-interview-question-2/</link>
		<comments>http://zcentric.com/2011/01/14/senior-linux-admin-interview-question-2/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 13:22:35 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Sys Admin]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=223</guid>
		<description><![CDATA[You can see all the questions I have compiled here. Question You are already logged into a server and a user runs a fork bomb script. How can you stop the fork bomb without restarting the server or bringing any services offline that are currently running? You also know the name of the running fork [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F01%2F14%2Fsenior-linux-admin-interview-question-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F01%2F14%2Fsenior-linux-admin-interview-question-2%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>You can see all the questions I have compiled <a href="http://zcentric.com/category/interview-questions/">here</a>.</p>
<h2>Question</h2>
<p>You are already logged into a server and a user runs a <a href="http://en.wikipedia.org/wiki/Fork_bomb" target="_blank">fork bomb</a> script. How can you stop the fork bomb without restarting the server or bringing any services offline that are currently running?</p>
<p>You also know the name of the running fork bomb script.</p>
<h2>Reason for the this question</h2>
<p>This will tell you how well the canidate knows about the signals Linux uses with processes. I would think most people would say the easy thing</p>
<p><code>killall -9 scriptName</code></p>
<p>This will not work due the nature of a fork bomb. The reason is the killall does not hold a lock on the process table so each one that is killed a new one takes its place in the process table. </p>
<p>Also you will not be able to run a killall due to the shell forking off another shell to run the killall</p>
<p>This question also tells you if the admin knows about Linux internals. That just running a killall will fork a new process buy running exec killall will run the killall in the current process and not fork out a new one</p>
<h2>Answer</h2>
<p>So for this I will use a fork bomb script that is written in C. Below is an example</p>
<pre><code>#include <unistd.h>

int main(void)
{
  for(;;)
    fork();
  return 0;
}</code></pre>
<p>We can compile it like</p>
<p><code>gcc -o fork fork.c</code></p>
<p>So the way to stop it is sending a SIGSTOP signal to each fork bomb process and once they are all stopped you can send a SIGKILL to each process. </p>
<p>So if you run a </p>
<p><code>killall -STOP fork</code></p>
<p>You will get a error message like resources not avaliable so you cannot run that. You can run it with exec.</p>
<pre><code>exec killall -STOP fork
exec killall -9 fork</code></pre>
<p>That will stop the fork bomb. </p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/01/14/senior-linux-admin-interview-question-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Senior Linux Admin Interview Question #1</title>
		<link>http://zcentric.com/2011/01/13/senior-linux-admin-interview-question-1/</link>
		<comments>http://zcentric.com/2011/01/13/senior-linux-admin-interview-question-1/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 19:37:28 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Sys Admin]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=219</guid>
		<description><![CDATA[So I&#8217;m starting a bit of a series on my blog. I&#8217;ve found there are no good senior level Linux admin questions out there to ask. A lot of companies with a sys admin team have their default questions they ask but when you are hiring your first sys admin and want a senior guy [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F01%2F13%2Fsenior-linux-admin-interview-question-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F01%2F13%2Fsenior-linux-admin-interview-question-1%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>So I&#8217;m starting a bit of a series on my blog. I&#8217;ve found there are no good senior level Linux admin questions out there to ask. A lot of companies with a sys admin team have their default questions they ask but when you are hiring your first sys admin and want a senior guy there is no real way to tell how good he is if no one on your team knows Linux all that well.</p>
<p>So maybe some of these will help some companies figure it all out.</p>
<h2>Question</h2>
<p>The server is running Apache and by mistake one of the log files gets deleted via</p>
<p><code>rm domain.com-access_log</code></p>
<p>Without installing any 3rd party recovery tools how can you recover this file that your boss needs. Also assume that as soon as the log file was deleted that Apache was not restarted.</p>
<h2>Reason for this question</h2>
<p>This is a really tough question to answer. I would think a lot of senior guys might not even know the answer to this. I certainly did not when I got it asked by Google five years ago.</p>
<p>If the person gets it right I would say he has a really great grasp on how Linux /proc system works and I would say he is a pretty solid admin if he answered all your other questions correctly</p>
<h2>Answer</h2>
<p>So the simple answer is the deleted file is still held open by Apache so it can still be recovered in the /proc filesystem.</p>
<p>So here is how to get to it. For example I have a really small access_log</p>
<p><code>﻿﻿﻿﻿  4 -rw-r--r--   1 root root   2262 Jan 13 12:32 access_log</code></p>
<p>So lets remove it</p>
<p><code>rm -f access_log</code></p>
<p>So the file has been deleted now. So lets find the process number for the main apache process. It will be owned by root</p>
<pre><code>[root@laptop httpd]# ps aux | grep httpd
root      8070  0.0  0.3  38468 10948 ?        Ss   12:31   0:00 /usr/sbin/httpd
apache    8072  0.0  0.1  38388  5844 ?        S    12:31   0:00 /usr/sbin/httpd
apache    8073  0.0  0.3  40752 11532 ?        S    12:31   0:00 /usr/sbin/httpd</code></pre>
<p>So we see that the pid for the main apache process is 8070. So now lets list the file descriptors </p>
<p><code>ls -lsa /proc/8070/fd</code></p>
<p>We get something like</p>
<p><code>0 l-wx------ 1 root root 64 Jan 13 12:34 11 -> /var/log/httpd/access_log (deleted)</code></p>
<p>As you can see that is our file and its marked as deleted.. so we can do </p>
<p><code>cp /proc/8070/fd/11 /tmp/access_log</code></p>
<p>Then from there you can stop apache.. move the access_log in its correct place and start apache back up</p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/01/13/senior-linux-admin-interview-question-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>One of my most hated interview questions use to be &#8220;How many IPs in this subnet?&#8221;</title>
		<link>http://zcentric.com/2011/01/13/one-of-my-most-hated-interview-questions-use-to-be-how-many-ips-in-this-subnet/</link>
		<comments>http://zcentric.com/2011/01/13/one-of-my-most-hated-interview-questions-use-to-be-how-many-ips-in-this-subnet/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 16:50:26 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Sys Admin]]></category>

		<guid isPermaLink="false">http://zcentric.com/?p=216</guid>
		<description><![CDATA[I use to hate this question. I was reading a post on Reddit about some guy that went through the programming interview at Facebook and it made me remember the simple interview question I always hated answering. It always went something like this How many usable IPs in a /24 Ok that is an easy [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fzcentric.com%2F2011%2F01%2F13%2Fone-of-my-most-hated-interview-questions-use-to-be-how-many-ips-in-this-subnet%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fzcentric.com%2F2011%2F01%2F13%2Fone-of-my-most-hated-interview-questions-use-to-be-how-many-ips-in-this-subnet%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I use to hate this question. I was reading a post on Reddit about some guy that went through the programming interview at Facebook and it made me remember the simple interview question I always hated answering. It always went something like this</p>
<p>How many usable IPs in a /24</p>
<p>Ok that is an easy one.. 256-2=254 not a big deal.. next!</p>
<p>Then they would ask</p>
<p>How many usable IPs in a /28</p>
<p>That is what usually made me say &#8220;Networking is not really my strong point&#8221; Well got that one wrong.. So I went out to fix this many many years ago. Well there&#8217;s an easy step you can do in your head. </p>
<p>All subnets going up are half of the one below it. So your /24 would have 256 IPs in it. So it would go like this</p>
<pre><code>/25 = 128
/26 = 64
/27 = 32
/28 = 16</code></pre>
<p>So there was my answer 16 IPs and 14 are usable. Its really that easy to figure out. Anything between /24 and /32 is easy to figure out if you can easily do the math in your head like that. You can do the oppsite if they give you a /29</p>
<pre><code>/32 = 1
/31 = 2
/30 = 4
/29 = 8</code></pre>
<p>Now there is also a little math formula you can use also. </p>
<p>So back to our question.. If we want to know how many usably IPs in a /28. We would go like</p>
<p><code>2^(32-28) - 2</code> </p>
<p>Which would be</p>
<p><code>(2^4) - 2 = 14</code></p>
<p>That broken down is like saying</p>
<p><code>(2*2*2*2) - 2  = 14</code></p>
<p>When you toss exponents in it gets a bit rough but its easier if they tell you.. So how many in a /20</p>
<p><code>(2^(32-20)) = 4096</code></p>
<p>We won&#8217;t worry about usable in this case because it depends how you will subnet it off. </p>
]]></content:encoded>
			<wfw:commentRss>http://zcentric.com/2011/01/13/one-of-my-most-hated-interview-questions-use-to-be-how-many-ips-in-this-subnet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

