<?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>ITSA Blog &#187; Linux</title>
	<atom:link href="http://itsecureadmin.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://itsecureadmin.com</link>
	<description>Life as an Open Source Solutions Architect.</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:38: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>List MySQL Table Space Consumption</title>
		<link>http://itsecureadmin.com/2011/12/list-mysql-table-space-consumption/</link>
		<comments>http://itsecureadmin.com/2011/12/list-mysql-table-space-consumption/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 18:44:12 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>
		<category><![CDATA[Tip of the day!]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/2011/12/list-mysql-table-space-consumption/</guid>
		<description><![CDATA[Have you ever needed to print out a list of each table within MySQL and how much space was consumed?
Try this to list the top 20 space offenders:

SELECT engine, concat( table_schema, '.', table_name ) table_name,
concat( round( data_length / ( 1024 *1024 ) , 2 ) , 'M' ) data_length,
concat( round( index_length / ( 1024 *1024 [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed to print out a list of each table within MySQL and how much space was consumed?</p>
<p>Try this to list the top 20 space offenders:</p>
<pre>
SELECT engine, concat( table_schema, '.', table_name ) table_name,
concat( round( data_length / ( 1024 *1024 ) , 2 ) , 'M' ) data_length,
concat( round( index_length / ( 1024 *1024 ) , 2 ) , 'M' ) index_length,
concat( round( round( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , 'M' ) total_size
FROM information_schema.TABLES
ORDER BY ( data_length + index_length ) DESC LIMIT 20
</pre>
<p>Taken from a comment on the mysql developer docs site:  http://dev.mysql.com/doc/refman/5.1/en/tables-table.html</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2011/12/list-mysql-table-space-consumption/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Domain Auto-Enrollment / Hostname Management with Powershell (v2)</title>
		<link>http://itsecureadmin.com/2011/08/domain-auto-enrollment-hostname-management-with-powershell-v2/</link>
		<comments>http://itsecureadmin.com/2011/08/domain-auto-enrollment-hostname-management-with-powershell-v2/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 15:58:30 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/?p=222</guid>
		<description><![CDATA[I am realizing now that I need to get a git repo setup that is publicly accessible which will allow me to share scripts and other code snippets that I&#8217;m working on.
Here is the second iteration of the powershell domain/hostname management script that I&#8217;m working on.  It will also update the SQL Server dbname [...]]]></description>
			<content:encoded><![CDATA[<p>I am realizing now that I need to get a git repo setup that is publicly accessible which will allow me to share scripts and other code snippets that I&#8217;m working on.</p>
<p>Here is the second iteration of the powershell domain/hostname management script that I&#8217;m working on.  It will also update the SQL Server dbname to reflect the hostname change on SQL Server 2008 boxes.</p>
<pre>
# This script will re-initialize domain membership and change the hostname to reflect the
# hexadecimal representation of the IP address assigned on boot.
#
# Author:  Josh Miller
# Date:    8/12/2011
#
# Note that there are 4 possible conditions that a host may come up in:
# 1. valid domain, invalid hostname
#    (although domain membership is invalid)
# 2. invalid domain, invalid hostname
# 3. invalid domain, valid hostname
# 4. valid domain, valid hostname
#
# The actions that will be taken for each of these conditons are:
# 1. leave domain, reboot
# 2. change hostname, reboot
# 3. join domain, reboot
# 4. do nothing, final condition
#
# Setup:
# 1. setup scheduled task to run on start-up as local administrator
# 2. create bat file to execute this powershell script, ie:
#   powershell -command "&amp; 'c:\tools\powershell\domain.ps1' "
# 3. create AMI/template on network with DHCP
# 4. join to domain
# 5. verify that scheduled task is running as local administrator, bear
#    in mind that hostnames change frequently and just before you clone/
#    create the AMI, set the credentials again.
#
# Note:  this should really not work.  Once the hostname changes and the
#        machine reboots, it should not have permission to run one more
#        time to join the domain.  I don't understand why it works.  The
#        next run fails due to lack of permissions which is understandable
#        and acceptable.
#

# join domain values
$domain = "domain.com"
$user   = "domain\ad_user"
$pass   = "mysecret"

$secpassword = ConvertTo-SecureString $pass -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($user, $secpassword)

# hostname to operate against - typically this host
$scripthost = get-content env:computername

# Leave the domain.
function LeaveDomain {

  Add-Computer -WorkGroupName "WorkGroup" -Credential $credentials

}

# Join the domain.
function JoinDomain {

  Add-Computer -DomainName $domain -Credential $credentials

}

# Restart the machine
function RestartMachine {

  Restart-Computer -Force

}

# Function to set hostname to hexadecimal representation of IP address
function SetHexHostname ([string] $setHostName) {

  # Return value of 5    means 'Access denied'.
  # Return value of 1326 means 'Logon failure: unknown username or bad password'.

  $computerinfo = Get-WmiObject -Class Win32_ComputerSystem
  $computerinfo.Rename( $setHostName )

}

# Function to get hostname as hexadecimal representation of IP address
function GetHexHostname {

  $getHostName = "" ;

  # Get IP Address of host
  $myIpAddress = "{0:x}" -f (Get-WmiObject Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null}).ipaddress

  # split ip into 4 octets, prep to convert to hexadecimal
  $octets = $myIpAddress.split(".")

  foreach ($octet in $octets) {

    $hexOctet = [System.String]::Format("{0:X}",[System.Convert]::ToUInt32($octet))

    # Prepend 0 to beginning if less than 2 digits
    if ( $hexOctet.Length -lt 2 ) {
      $hexOctet = "0" + "$hexOctet"
    }

    $getHostName = "$getHostName" + "$hexOctet"
  }

  $getHostName = "IP-" +  $getHostName

  Return $getHostName

}

# Function updates the dbname with hostname - always assumes needs changed.
function SetDBName ([string] $setDBName) {

  # Get SQL server version
  #  8.x = 2000
  #  9.x = 2005
  # 10.x = 2008
  $server_version = Invoke-Sqlcmd -Query "Select serverproperty('productversion') as version;"
  $sql_version    = $server_version.version

  if ( $sql_version -lt 9 ) {

    # works for sql2000
    $results = Invoke-Sqlcmd -Query "select srvname from sysservers;"
    $current_dbname = $results.srvname

  } else {

    # works for sql2005/2008
    $results = Invoke-Sqlcmd -Query "select name from sys.servers;"
    $current_dbname = $results.name

  }

  if ( $setDBName.CompareTo($current_dbname) -ne 0 ) {

    Write-Host "Updating DBName to match hostname"

    $drop_dbname = Invoke-Sqlcmd -Query "exec sp_dropserver '$current_dbname';"
    $add_dbname  = Invoke-Sqlcmd -Query "exec sp_addserver  '$setDBName', local;"

  }

}

#                                       #
# Start program execution.  #
#                                       #

# Ensure hostname is properly set
$testHostname = GetHexHostname

# Is admin share available?
if ( ! ( Test-Path \\$scripthost\admin$ ) -eq "TRUE") {
  Write-Host "Unable to access admin share."
  exit
}

$ObjReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $scripthost)
$ObjRegKey = $ObjReg.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters")
$DomName = $ObjRegKey.GetValue("Domain")

if ( $DomName -eq $domain ) {

  Write-Host "Valid domain."

  if ( $testHostName.CompareTo( $scripthost ) -ne 0 ) {

    Write-Host "Invalid hostname, leaving domain."

    LeaveDomain
    RestartMachine

  } else {

    Write-Host "Valid domain and hostname."

  }

} else {

  Write-Host "Invalid domain."

  if ( $testHostName.CompareTo( $scripthost ) -ne 0 ) {

    Write-Host "Hostname not set correctly, setting to $testHostName"
    SetHexHostname ( $testHostname )
    SetDBName ( $testHostname )

  } else {

    Write-Host "Valid hostname, joining domain."
    JoinDomain

  }

  # Restart after either changing hostname or joining domain.
  RestartMachine

}
</pre>
<p>As always, let me know if you have any improvements, bugs, suggestions, etc.. at:<br />
    linux (at) itsecureadmin (dot) com</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2011/08/domain-auto-enrollment-hostname-management-with-powershell-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bind-DLZ with MySQL</title>
		<link>http://itsecureadmin.com/2010/09/bind-dlz-with-mysql/</link>
		<comments>http://itsecureadmin.com/2010/09/bind-dlz-with-mysql/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 18:23:22 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/?p=115</guid>
		<description><![CDATA[DNS management with Bind has traditionally been flat files and slave/master configurations.  Bind also has a feature/extension called DLZ &#8212; dynamically loaded zones.  This feature can be very useful when designing applications that use databases or directories for storage rather than having to design your application to address a filesystem to create resource [...]]]></description>
			<content:encoded><![CDATA[<p>DNS management with Bind has traditionally been flat files and slave/master configurations.  Bind also has a feature/extension called DLZ &#8212; dynamically loaded zones.  This feature can be very useful when designing applications that use databases or directories for storage rather than having to design your application to address a filesystem to create resource records or zone files.</p>
<p>In this article, I will explain how to set this up for a configuration where there are thousands of name-based virtual hosts hosted on the same VIP/email infrastructure using the same resource record on a CentOS 5.X system using MySQL to store records.  The Bind version is 9.6.0-P1.</p>
<p>The first step is to install any pre-requisites:</p>
<pre>
yum install openssl-devel mysql-devel openldap-devel unixODBC-devel gcc
</pre>
<p>Note that you&#8217;ll want to uninstall <code>gcc</code> after this process is complete to reduce the likelihood of an attacker compiling an exploit on this box if they were to gain unprivileged access.</p>
<p>Next, download and extract the Bind sources:</p>
<pre>
pushd /tmp/
curl -C - -L -O 'http://ftp.isc.org/isc/bind9/9.6.0-P1/bind-9.6.0-P1.tar.gz'
tar xzvf bind-9.6.0-P1.tar.gz
pushd bind-9.6.0-P1
</pre>
<p>If compiling on a 64 bit system, you might have to setup some variables so that the appropriate mysql libraries are found:<br />
<code><br />
export CPPFLAGS="-I/usr/lib64/mysql $CPPFLAGS"<br />
export LDFLAGS="-L/usr/lib64/mysql $LDFLAGS"<br />
export LD_LIBRARY_PATH="/usr/lib64/mysql"<br />
</code></p>
<p>The next step is to run configure &#8212; this example uses mysql only:</p>
<pre>
./configure  \
  --prefix=/usr/local/bind  \
  --disable-openssl-version-check \
  --with-dlz-mysql=yes
</pre>
<p>Once successful with configure, the next step is to install:<br />
<code><br />
make &amp;&amp; sudo make install<br />
</code></p>
<p>Be sure to add a user and group, as well as setup some basic directories for data:<br />
<code><br />
groupadd -r -g 25 named<br />
useradd -r -u 25 -s /bin/nologin -d /usr/local/named -g named named<br />
mkdir /var/cache/bind<br />
chown named:named /var/cache/bind<br />
</code></p>
<p>Now that the easy part is finished, the next step is to setup MySQL to store the appropriate DNS records.</p>
<p>In this example, data is populated in MySQL via a stored procedure in SQL Server via a linked server to a MySQL master (ODBC).  A python script then creates the necessary entries in the postfix database to allow mail routing to occur.  One of the tables populated here is the postfix.domains table.  This is simply a list of all domains that are hosted at this site.  I take advantage of this to replicate only this table to each of my DNS servers running MySQL and Bind-DLZ locally.  This explanation will help the reader understand the next portion where I setup tables and views and populate them with data.</p>
<p>The next step is to create the database which will store the records.  I use a database called postfix since my setup is tightly coupled with email routing and replication from the email database.  (Login to MySQL to perform the following actions or script as appropriate.)<br />
<code><br />
mysql&gt; create database postfix;<br />
</code></p>
<p>Next, I create a template of resource records that will apply to all zones hosted within MySQL.  (Note that this is a site which hosts thousands of domains on the same VIP/email architecture.)</p>
<pre>
DROP TABLE IF EXISTS dns_values;
CREATE TABLE dns_values (
  host VARCHAR(255) DEFAULT '' NOT NULL,
  type ENUM('SOA','NS','MX','A','CNAME','TXT','HINFO','PTR') NOT NULL DEFAULT 'SOA',
  data VARCHAR(255),
  ttl INT(11) DEFAULT 300 NOT NULL,
  mx_priority VARCHAR(10),
  refresh INT(11) DEFAULT 0 NOT NULL,
  retry INT(11) DEFAULT 0 NOT NULL,
  expire INT(11) DEFAULT 0 NOT NULL,
  minimum INT(11) DEFAULT 0 NOT NULL,
  serial BIGINT(20) DEFAULT 0 NOT NULL,
  resp_person VARCHAR(255),
  primary_ns VARCHAR(255),
  key host_index (host),
  key type_index (type)
) ENGINE=MyISAM;
</pre>
<p>The next step is to populate the basic set:<br />
<code><br />
mysql&gt; LOCK TABLES `dns_values` WRITE;<br />
/*!40000 ALTER TABLE `dns_values` DISABLE KEYS */;<br />
INSERT INTO `dns_values` VALUES<br />
('@','SOA','root.mail.example.com.',300,NULL,10800,900,604800,600,2009020401,'root.mail.example.com.','ns1.example.com.'),<br />
('@','NS','ns1.example.com.',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('@','NS','ns2.example.com.',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('@','A','xxx.xxx.xxx.xxx',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('images','A','xxx.xxx.xxx.xxx',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('mail','A','xxx.xxx.xxx.xxx',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('*','A','xxx.xxx.xxx.xxx',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('imap','CNAME','mail.example.com.',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('smtp','CNAME','mail.example.com.',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('@','TXT','v=spf2.0/pra mx ip4:xxx.xxx.xxx.0/24 -all',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('@','TXT','v=spf1 mx ip4:xxx.xxx.xxx.0/24 -all',300,NULL,10800,900,604800,600,2009020401,NULL,NULL),<br />
('@','MX','mail.example.com.',300,'10',10800,900,604800,600,2009020401,NULL,NULL),<br />
('webmail','CNAME','mail.example.com.',300,NULL,10800,900,604800,600,2009020401,NULL,NULL);<br />
/*!40000 ALTER TABLE `dns_values` ENABLE KEYS */;<br />
UNLOCK TABLES;<br />
</code></p>
<p>Create the postfix.domains table:</p>
<pre>
mysql&gt; CREATE TABLE domains (
  domain varchar(128) NOT NULL default '',
  PRIMARY KEY  (domain)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
</pre>
<p>Go ahead and populate the domains table with some values.  Note that I replicate data from another table but you can just as well enter any values manually.<br />
<code><br />
mysql&gt; insert into domains (domain) values('example.com');<br />
</code></p>
<p>The next step is to create a view that will combine the dns_values table with the domains table to present all records as one table:</p>
<pre>
mysql&gt;CREATE VIEW dns_records AS
SELECT
  d.domain        as zone
  ,dv.host        as host
  ,dv.type        as type
  ,dv.data        as data
  ,dv.ttl         as ttl
  ,dv.mx_priority as mx_priority
  ,dv.refresh     as refresh
  ,dv.retry       as retry
  ,dv.expire      as expire
  ,dv.minimum     as minimum
  ,dv.serial      as serial
  ,dv.resp_person as resp_person
  ,dv.primary_ns  as primary_ns
FROM domains d, dns_values dv ;
</pre>
<p>Next, setup grants on MySQL to allow the user who is accessing MySQL from Bind access:<br />
<code><br />
mysql&gt; GRANT USAGE,SELECT ON postfix.* TO binddlz@localhost identified by 'trickypassword';<br />
FLUSH PRIVILEGES;<br />
</code></p>
<p>I started with a pretty basic named.conf file:</p>
<pre>
key rndc {
  algorithm hmac-md5 ;
  secret "longsecret";
};

controls {
  inet 127.0.0.1 allow { localhost; } keys { rndc; };
};

include "/usr/local/bind/etc/named.conf.options";

// prime the server with knowledge of the root servers
zone "." {
  type hint;
  file "/usr/local/bind/etc/db.root";
};

// setup local zones
zone "localhost" {
  type master;
  file "/usr/local/bind/etc/db.local";
};

zone "127.in-addr.arpa" {
  type master;
  file "/usr/local/bind/etc/db.127";
};

zone "0.in-addr.arpa" {
  type master;
  file "/usr/local/bind/etc/db.0";
};

zone "255.in-addr.arpa" {
  type master;
  file "/usr/local/bind/etc/db.255";
};

include "/usr/local/bind/etc/named.custom.zones";
include "/usr/local/bind/etc/named.dlz.zones";
</pre>
<p>As far as <code>named.conf.options</code>, it is also pretty basic:</p>
<pre>
options {
  directory "/var/cache/bind";
  allow-transfer { xxx.xxx.xxx.xxx; xxx.xxx.xxx.xxx; };
  zone-statistics yes;
  statistics-file "/usr/local/bind/var/stats/named-stats.out";
  recursion no;
};
</pre>
<p>As you can see, I simply included the following configuration portion as <code>named.dlz.zones</code>.</p>
<pre>
dlz "mysql zone" {
  database "mysql
  {host=localhost dbname=postfix user=binddlz pass=trickypassword ssl=false}
  {select zone from dns_records where zone = '%zone%'}
  {select ttl, type, mx_priority, case
      when lower(type)='txt' then concat('\"', data, '\"')
      when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum)
    else data end from dns_records_view where zone = '%zone%' and host = '%record%'}";
};
</pre>
<p>Now start Bind with the following command and test:<br />
<code><br />
/usr/local/bind/sbin/named -c /usr/local/bind/etc/named.conf -f -g -u named<br />
</code></p>
<p>Useful tips:<br />
* do not include both ns and contact in SOA record, use only respo_contact in either data or resp_contact fields<br />
* make sure you restart Bind every time you restart MySQL or you will lose your connection(s)<br />
* if you would like to create the dns_records table without a view, simply use the dns_values table and add  the zone as the first column</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2010/09/bind-dlz-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expanding an ext3 filesystem online</title>
		<link>http://itsecureadmin.com/2010/03/expanding-an-ext3-filesystem-online/</link>
		<comments>http://itsecureadmin.com/2010/03/expanding-an-ext3-filesystem-online/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 21:52:05 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/?p=79</guid>
		<description><![CDATA[One common scenario that I face in my daily work is to add disk to various filesystems.  Setting up systems correctly so that this is possible will save time and frustration.  One of the easiest cases is adding disk to a virtual machine when the guest is using LVM and ext3.
As always, please [...]]]></description>
			<content:encoded><![CDATA[<p>One common scenario that I face in my daily work is to add disk to various filesystems.  Setting up systems correctly so that this is possible will save time and frustration.  One of the easiest cases is adding disk to a virtual machine when the guest is using LVM and ext3.</p>
<p>As always, please be sure to backup your data before trying any filesystem or disk manipulation.</p>
<p>After adding the virtual hard disk using the VI client, provision the space from within the virtual machine using the following steps:</p>
<p>1. re-scan storage</p>
<pre>echo "- - -" &gt; /sys/class/scsi_host/host0/scan</pre>
<p>2. Create physical volume from new device  (Note:  check with your SAN admin to see if you need to create a partition and align appropriately.)</p>
<pre>pvcreate /dev/sdb</pre>
<p>3. Extend the volume group to the new PV (physical volume):</p>
<pre>vgextend vg01 /dev/sdb</pre>
<p>3. Extend the LV (logical volume) to the desired size:</p>
<pre>lvextend -L +2G /dev/vg01/lvol05</pre>
<p>4. Resize the filesystem to cover the newly extended LV:</p>
<pre>resize2fs /dev/vg01/lvol05</pre>
<p>Your newly resized filesystem should now be available.</p>
<p><em>I have not  yet tried expanding existing VMDK files on the fly with vSphere but I plan to test that out next.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2010/03/expanding-an-ext3-filesystem-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash Tip!  Renaming files using Bash string operations</title>
		<link>http://itsecureadmin.com/2010/01/bash-tip-renaming-files-using-bash-string-operations/</link>
		<comments>http://itsecureadmin.com/2010/01/bash-tip-renaming-files-using-bash-string-operations/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 05:47:47 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>
		<category><![CDATA[Tip of the day!]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/blog/?p=44</guid>
		<description><![CDATA[To rename all html files in a particular directory to shtml files, use the following loop:
for file in *.html
do
  mv ${file} ${file%%.html}.shtml
done
This uses the ${variable%%match} format which strips the longest match from the end of the variable.
]]></description>
			<content:encoded><![CDATA[<p>To rename all html files in a particular directory to shtml files, use the following loop:</p>
<pre>for file in *.html
do
  mv ${file} ${file%%.html}.shtml
done</pre>
<p>This uses the ${variable%%match} format which strips the longest match from the end of the variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2010/01/bash-tip-renaming-files-using-bash-string-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Persistent Debian Daemons</title>
		<link>http://itsecureadmin.com/2009/05/persistent-debian-daemons/</link>
		<comments>http://itsecureadmin.com/2009/05/persistent-debian-daemons/#comments</comments>
		<pubDate>Tue, 12 May 2009 15:34:59 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/blog/?p=32</guid>
		<description><![CDATA[As a long time Redhat / Fedora user, starting daemons on system boot in Debian has been a mystery.  I recently took the time to search for the answer, rather than placing the start command in the rc.local file and it&#8217;s not that bad.  As long as the init script exists in /etc/init.d, run the [...]]]></description>
			<content:encoded><![CDATA[<p>As a long time Redhat / Fedora user, starting daemons on system boot in Debian has been a mystery.  I recently took the time to search for the answer, rather than placing the start command in the rc.local file and it&#8217;s not that bad.  As long as the init script exists in /etc/init.d, run the following command to set it to persist:</p>
<pre>
update-rc.d &lt;daemon&gt;  defaults
</pre>
<p>This handy tip was taken from the official debian docs at:</p>
<p>http://www.debian.org/doc/FAQ/ch-customizing.en.html</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2009/05/persistent-debian-daemons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replacing a MySQL Master Node</title>
		<link>http://itsecureadmin.com/2009/05/replacing-a-mysql-master-node/</link>
		<comments>http://itsecureadmin.com/2009/05/replacing-a-mysql-master-node/#comments</comments>
		<pubDate>Fri, 01 May 2009 15:34:29 +0000</pubDate>
		<dc:creator>Josh Miller, Red Hat Certified Engineer</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/blog/?p=28</guid>
		<description><![CDATA[I recently had to build out a new MySQL node and replace an existing replication master.  Here is the basic procedure that I followed.
1. Build out the new server
2. Install MySQL.  Place the data directory on a logical volume with at least 10% free space in the volume  group (for snapshot backups).
3. Take a good [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to build out a new MySQL node and replace an existing replication master.  Here is the basic procedure that I followed.</p>
<p>1. Build out the new server<br />
2. Install MySQL.  Place the data directory on a logical volume with at least 10% free space in the volume  group (for snapshot backups).<br />
3. Take a good backup of the database(s) from an existing slave.<br />
4. Restore backup to newly built server/mysql instance.<br />
5. Set master to current master.<br />
6. Lock tables on master.<br />
7. Cut over to new master when replication is caught up.</p>
<p>I won&#8217;t belabor the issue of building out a server or installing MySQL.  I used CentOS 5.3 and the Percona 5.0.77 binaries for this server.</p>
<p><strong>Taking a Restorable Backup from an Existing Slave</strong></p>
<p>In order to create a point in time restorable backup, it is necessary to stop all writes to the database.  In order to do this on the slave, I simply stopped replication.  This is easily done with the &#8217;stop slave;&#8217; command.</p>
<p>mysql&gt; stop slave;<br />
Query OK, 0 rows affected (0.12 sec)</p>
<p>Also, issue a &#8217;show slave status\G&#8217; and note the master log file name and position.  This will be used to setup replication on the new master which will allow it to sync with the current master.</p>
<p>To perform the backup, I used a combination of mysqlhotcopy and mysqldump.  In this case, I only had &lt; 1MB of data in InnoDB tables and 40GB of data in MyISAM tables.  Mysqlhotcopy is used to backup the MyISAM data while mysqldump is used for the InnoDB data.  Note that unless you stop the slave this will not allow a perfect point in time backup as the InnoDB tables might be changed between the time the mysqlhotcopy finishes and the mysqldump finishes.</p>
<p>After the backup is complete, start the slave thread on the MySQL instance where the backup was taken.</p>
<p>mysql&gt; start slave;<br />
Query OK, 0 rows affected (0.10 sec)</p>
<p><strong>Restore Backup to New Server</strong></p>
<p>To restore the backup, I copied the MyISAM files to the data directory on the destination host and chown&#8217;ed them to be owned by the mysql user and group.  I then started the MySQL server instance and imported the mysqldump data using the  mysql command.</p>
<p><strong>Set (new) Master to Current Master</strong></p>
<p>First, verify that the replication-user has access to the current master from the new master.  Once this is verified, set the current master by issuing the following command (or similar) on the new master.  This will allow the new master to sync data with the current master.</p>
<p>CHANGE MASTER TO<br />
MASTER_HOST=&#8217;192.168.1.154&#8242;,<br />
MASTER_USER=&#8217;replication-user&#8217;,<br />
MASTER_PASSWORD=&#8217;replication-password&#8217;,<br />
MASTER_LOG_FILE=&#8217;mysql-bin.00574&#8242;,<br />
MASTER_LOG_POS=28347586;</p>
<p>You should be able to issue a &#8217;show slave status\G&#8217; command and see that replication is behind and catching up.</p>
<p>Once replication is caught up, it is safe to cut over to the new master.  In order to do this, all writes to the current master must be stopped and the new master must be allowed to be completely synched as far as replication is concerned.</p>
<p>Old master node:</p>
<p>mysql&gt; flush tables with read lock;</p>
<p>Once this occurs, set any existing slaves to the new master and stop using the old master.  Also, stop the slave on the new master, set &#8216;reset slave;&#8217; to remove all &#8220;master&#8221; variables.</p>
<p>New master node:</p>
<p>mysql&gt; stop slave; reset slave;</p>
<p>Current slave nodes (use show master status on new master to get file name and position):</p>
<blockquote><p>CHANGE MASTER TO<br />
MASTER_HOST=&#8217;&lt;IP of new master&gt;&#8217;,<br />
MASTER_USER=&#8217;replication-user&#8217;,<br />
MASTER_PASSWORD=&#8217;replication-password&#8217;,<br />
MASTER_LOG_FILE=&#8217;mysql-bin.00574&#8242;,<br />
MASTER_LOG_POS=28347586;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2009/05/replacing-a-mysql-master-node/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sony Cybershot with Fedora 9</title>
		<link>http://itsecureadmin.com/2008/08/sony-cybershot-with-fedora-9/</link>
		<comments>http://itsecureadmin.com/2008/08/sony-cybershot-with-fedora-9/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 21:32:02 +0000</pubDate>
		<dc:creator>Josh Miller, RHCE</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/blog/?p=19</guid>
		<description><![CDATA[While attempting to dump some photos from my newly acquired Sony Cybershot camera onto a Fedora 9 workstation, I had to switch to &#8220;Mass Storage&#8221; mode on the camera before I was able to mount the volume.
When I inserted the USB cable into my camera and turned it on, the dmesg output was as follows:

usb [...]]]></description>
			<content:encoded><![CDATA[<p>While attempting to dump some photos from my newly acquired Sony Cybershot camera onto a Fedora 9 workstation, I had to switch to &#8220;Mass Storage&#8221; mode on the camera before I was able to mount the volume.</p>
<p>When I inserted the USB cable into my camera and turned it on, the dmesg output was as follows:</p>
<pre>
usb 1-6: new high speed USB device using ehci_hcd and address 3
usb 1-6: configuration #1 chosen from 2 choices
usb 1-6: New USB device found, idVendor=054c, idProduct=0010
usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-6: Product: Sony DSC
usb 1-6: Manufacturer: Sony
</pre>
<p>I saw an  Ubuntu forum note about switching to PTP mode, but that did not work for me, only returning the following:</p>
<pre>
usb 1-6: new high speed USB device using ehci_hcd and address 4
usb 1-6: configuration #1 chosen from 1 choice
usb 1-6: New USB device found, idVendor=054c, idProduct=004e
usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-6: Product: Sony PTP
usb 1-6: Manufacturer: Sony
</pre>
<p>After I switched to &#8220;Mass Storage&#8221; mode, I see the following output:</p>
<pre>
Initializing USB Mass Storage driver...
scsi4 : SCSI emulation for USB Mass Storage devices
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usb-storage: device found at 6
usb-storage: waiting for device to settle before scanning
usb-storage: device scan complete
scsi 4:0:0:0: Direct-Access     Sony     Sony DSC         6.00 PQ: 0 ANSI: 0 CCS
sd 4:0:0:0: [sdb] 3962880 512-byte hardware sectors (2029 MB)
sd 4:0:0:0: [sdb] Write Protect is off
sd 4:0:0:0: [sdb] Mode Sense: 00 00 00 00
sd 4:0:0:0: [sdb] Assuming drive cache: write through
sd 4:0:0:0: [sdb] 3962880 512-byte hardware sectors (2029 MB)
sd 4:0:0:0: [sdb] Write Protect is off
sd 4:0:0:0: [sdb] Mode Sense: 00 00 00 00
sd 4:0:0:0: [sdb] Assuming drive cache: write through
sdb: sdb1
sd 4:0:0:0: [sdb] Attached SCSI removable disk
sd 4:0:0:0: Attached scsi generic sg2 type 0
</pre>
<p>I was then able to mount the volume (was already mounted to /media/disk) and copy my pictures from the device.</p>
<pre>
$ lsusb
Bus 001 Device 006: ID 054c:0010 Sony Corp. DSC-S30/S70/S75/F505V/F505/FD92/W1 Cybershot/Mavica Digital Camera
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 0a81:0205 Chesen Electronics Corp. PS/2 Keyboard+Mouse Adapter
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2008/08/sony-cybershot-with-fedora-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vi Tip of the day!</title>
		<link>http://itsecureadmin.com/2008/07/vi-tip-of-the-day/</link>
		<comments>http://itsecureadmin.com/2008/07/vi-tip-of-the-day/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 16:53:35 +0000</pubDate>
		<dc:creator>Josh Miller, RHCE</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source Software]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://itsecureadmin.com/blog/?p=7</guid>
		<description><![CDATA[Something that I need to do frequently is to set some text to lowercase in vi which is currently in mixed or upper case.  A quick way to do this is:
:1s/\(.*\)/\L\1/
The above command acts on line 1 in the file, takes the entire line, enclosed in parentheses to create a group, then uses \L [...]]]></description>
			<content:encoded><![CDATA[<p>Something that I need to do frequently is to set some text to lowercase in vi which is currently in mixed or upper case.  A quick way to do this is:</p>
<p>:1s/\(.*\)/\L\1/</p>
<p>The above command acts on line 1 in the file, takes the entire line, enclosed in parentheses to create a group, then uses \L to specify lowercase on the entire line \1 that was previously matched.</p>
]]></content:encoded>
			<wfw:commentRss>http://itsecureadmin.com/2008/07/vi-tip-of-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

