tag:blogger.com,1999:blog-47319212708605688702023-06-20T21:08:38.064-07:00Easy Linux TricksValuable Tips For Linux Administrationchetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.comBlogger35125tag:blogger.com,1999:blog-4731921270860568870.post-31538419051163256322012-02-29T19:43:00.000-08:002012-02-29T19:43:58.372-08:00Collect bounced emails from postfix<div dir="ltr" style="text-align: left;" trbidi="on"># A ruby script for collecting bounced email with status<br />
require 'rubygems'<br />
path = "/var/spool/postfix/defer"<br />
defer = Dir.foreach("/var/spool/postfix/defer")<br />
<br />
defer.each do |x|<br />
x.gsub("..",'').gsub(".",'')<br />
if File.directory?("#{path}/#{x}")<br />
if Dir["#{path}/#{x}"].empty?<br />
# "is empty"<br />
else<br />
# "is not empty"<br />
a = x.gsub("..",'').gsub(".",'')<br />
if a == ''<br />
#<br />
else<br />
sub_dir = "#{path}/#{a}"<br />
Dir.foreach("#{sub_dir}") do |doc|<br />
sub_sub_dir = doc.gsub("..",'').gsub(".",'')<br />
<br />
if sub_sub_dir == ''<br />
#<br />
else<br />
contents = Array.new<br />
file = File.open("#{sub_dir}/#{sub_sub_dir}", "rb")<br />
file.each do |data|<br />
contents << data<br />
end <br />
output = Array.new<br />
arr = Array.new<br />
arr = contents.to_a.join<br />
arr.split("\n").each do |data|<br />
if data =~ /^recipient=/ <br />
output << data<br />
end<br />
if data =~ /^status/<br />
output << data<br />
end<br />
if data =~ /^reason/<br />
output << data<br />
end<br />
<br />
<br />
end<br />
puts " #{output[0]} | #{output[1]} | #{output[2]}"<br />
puts "!" <br />
end<br />
end <br />
<br />
end <br />
end <br />
<br />
else<br />
#<br />
end<br />
end<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-84357814239918131412012-01-06T23:33:00.000-08:002012-01-06T23:33:31.932-08:00RUBY CLIENT SERVER MONITOR<div dir="ltr" style="text-align: left;" trbidi="on"><br />
require "rubygems"<br />
require "socket"<br />
require "openssl"<br />
require "base64"<br />
include OpenSSL<br />
require "base64"<br />
PORT = 5534<br />
<br />
chat_client = TCPSocket.new("IP", PORT)<br />
<br />
<br />
# while line = gets do chat_client.puts(line) end<br />
$dpipe = `hostname`<br />
$dpipe = $dpipe.strip #squeeze.gsub(""," ")<br />
def load_check<br />
load_check = `uptime | cut -d: -f5 `<br />
$dpipe = $dpipe + "|"<br />
load ="#{load_check}".split(" ")<br />
load.each do<br />
|lcheck|<br />
$dpipe = $dpipe + lcheck #.squeeze.gsub("\n","")<br />
end <br />
end<br />
def disk_check<br />
array=`df -Ph | grep -r '/' | awk '{ printf "%s-%s-%s-%s ",$3,$4,$5,$6 }'`<br />
bulk_data="#{array}".split(" ")<br />
$dpipe = $dpipe + "|"<br />
bulk_data.each do<br />
|check|<br />
data="#{check}".split("-")<br />
max = data[2]<br />
if max.to_i > 90<br />
<br />
$dpipe = $dpipe + "Urgent:" + data[3] + ":" + data[2] + ":" + data[0] + ":" + data[1] + ","<br />
elsif max.to_i < 90 && max.to_i > 75<br />
$dpipe = $dpipe + "Warning:" + data[3] + ":" + data[2] + ":" + data[0] + ":" + data[1] + ","<br />
else<br />
<br />
end<br />
end<br />
end<br />
def apache_check<br />
apache_pid = `ps -efa | grep httpd | grep -v grep | awk '{ print $2 }'| xargs |wc -w`<br />
#puts apache_pid.to_i<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if apache_pid.to_i > 1<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$dpipe = $dpipe + "|"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$dpipe = $dpipe + "httpd:OK"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$dpipe = $dpipe + "|"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$dpipe = $dpipe + "httpd:NA"<br />
end<br />
end<br />
<br />
def mysql_check<br />
mysql_pid = `ps -efa | grep mysql | grep -v grep | awk '{ print $2 }'| xargs |wc -w`<br />
if mysql_pid.to_i > 1<br />
<br />
$dpipe = $dpipe + "|"<br />
$dpipe = $dpipe + "mysqld:OK"<br />
else<br />
$dpipe = $dpipe + "|"<br />
$dpipe = $dpipe + "mysqld:NA"<br />
end<br />
end<br />
<br />
def ram_check<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>m_array = `free -tom |xargs |cut -d ":" -f 2 |cut -d " " -f 1-7 |xargs`<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>mem_array="#{m_array}".split(" ")<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> threshold = ( ( mem_array[1].to_i - mem_array[5].to_i - mem_array[4].to_i ) * 100 ) / mem_array[0].to_i<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if threshold.to_i > 90<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "|"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "RAM:#{threshold.to_i}%:NA"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "|"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "RAM:#{threshold.to_i}%:ok"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>end<br />
end<br />
def process_check<br />
hallow = []<br />
p_array = `ps -eo pid,comm,%cpu,%mem | awk '{OFS="!"; print $1,$2,$3,$4}' | grep -v 'PID!COMMAND!%CPU!%MEM' |xargs `<br />
proc_list = "#{p_array}".split(" ")<br />
proc_list.each do |l|<br />
k = "#{l}".split("!")<br />
k.each do |lt|<br />
if k[2] != "0.0" or k[3] != "0.0"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if k[2].to_i > 50 or k[3].to_i > 20<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> hallow << l + ","<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>end<br />
end<br />
end<br />
end<br />
if hallow.length < 1<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "|"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "10PID:ok"<br />
else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> $dpipe = $dpipe + "|"<br />
$dpipe = $dpipe + "10PID:#{hallow}"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
end<br />
end<br />
load_check<br />
disk_check<br />
apache_check<br />
mysql_check<br />
ram_check<br />
process_check<br />
$dpipe.chomp<br />
#enc = Base64.encode64($dpipe)<br />
puts $dpipe<br />
hu = $dpipe<br />
#chat_client.puts(enc)<br />
#chat_client.puts($dpipe)<br />
chat_client.puts(hu)<br />
<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com1tag:blogger.com,1999:blog-4731921270860568870.post-90430514816439039932011-12-13T06:30:00.000-08:002011-12-13T06:30:09.610-08:00Script for installing redis-server under user<div dir="ltr" style="text-align: left;" trbidi="on"><br />
#! /bin/bash<br />
<br />
is_number()<br />
{<br />
echo "$1" | awk '$0 ~/[^0-9]/ { print "NA" }'>/tmp/numcheck$$$<br />
if [ "`cat /tmp/numcheck$$$|xargs`" == NA ] ;then<br />
echo "NA"<br />
fi<br />
}<br />
<br />
<br />
check_empty()<br />
{<br />
if [ "$1" == "" ] ;then<br />
echo "Blank input please try again !!!!!!!!!!!"<br />
exit<br />
else<br />
private=": ; = root passwd user `ls |xargs`"<br />
check=`echo $private |grep -w $1 |xargs`<br />
if [ "$check" != "" ] ;then<br />
echo "Reserved Word Please Retry :$private "<br />
exit<br />
fi<br />
fi<br />
}<br />
<br />
install_redis()<br />
{<br />
echo -e "\033[1m Redis server install Require sudoers user \033[0m"<br />
echo "Checking if redis already installed"<br />
sleep 3<br />
if [ -f "/usr/local/bin/redis-server" ] ; then<br />
echo "Redis installation already exits skipping source compile"<br />
if [ -f "/usr/bin/redis-server" ] ; then<br />
echo "Redis installation already exits skipping source compile"<br />
fi<br />
else<br />
cd ~/<br />
if [ -f "~/redis-2.2.14.tar.gz" ] ;then <br />
mv ~/redis-2.2.14* ~/redis-2.2.14_`date +%Y-%m-%d`<br />
fi<br />
wget http://redis.googlecode.com/files/redis-2.2.14.tar.gz<br />
tar xzf redis-2.2.14.tar.gz <br />
cd redis-2.2.14/ && make && sudo make install && mkdir -p ~/redis && sudo cp utils/redis_init_script /etc/init.d/Restart_Redis && cp redis.conf ~/redis/redis.conf && cd - && echo -e "\033[1m Enter the Redis port for custom application \033[0m" <br />
read port_input<br />
if [ "$port_input" == "" ] ; then<br />
echo "No redis port Specified continuing with default :recommends manual setting after Setup"<br />
port_check="`is_number $port_input |xargs`"<br />
if [ "$port_check" == "NA" ] ;then<br />
echo "invalid redis port Specified continuing with default :recommends manual setting after Setup"<br />
else<br />
echo "HELLO GOOD $port_input"<br />
fi<br />
fi<br />
fi<br />
}<br />
<br />
<br />
yes_no()<br />
{<br />
if [ "$*" != "yes" ] ; then<br />
echo "Thanks please try again ...."<br />
exit 1<br />
<br />
fi<br />
<br />
}<br />
<br />
install_redis<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-53784191582525758772011-05-31T00:01:00.000-07:002011-05-31T00:01:36.628-07:00Anaconda System installer stage1 initrd patching .<div dir="ltr" style="text-align: left;" trbidi="on"><span id="internal-source-marker_0.6774993618427647" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;"><a href="http://hi.baidu.com/delovery/blog/item/8a454d9085fd1181a877a42b.html">Reference : http://hi.baidu.com/delovery/blog/item/8a454d9085fd1181a877a42b.html</a> </span><br />
<br />
<span id="internal-source-marker_0.6774993618427647" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">Manually Update the Anaconda stage 1 image</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">WHAT IS THE STAGE 1 IMAGE?</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">The stage 1 image in anaconda confuses a lot of people. We've done a good job making stage 1 and stage 2 appear as a single entity, but they are really separate. The whole job of stage 1 is to load the necessary drivers to find anaconda (which we call the stage 2 image). Stage 2 could be located on a network source (NFS, HTTP, FTP), a local hard drive, or a CD-ROM drive. Stage 1 also takes care of configuring your network interface for installation if you indicate the stage 2 location is a network source.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">When a bug is found in stage 1, patching it and testing it requires building a new ramdisk image to boot in to the installation environment. We cannot provide a mechanism like updates.img for several reasons. First, the stage 1 portion of anaconda is responsible for loading updates.img after it loads. Second, the stage 1 portion is basically one static program called /sbin/loader, so the only way to test it is to build a new one.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">This document explains one of several ways to build a new stage 1 image for testing purposes. The example platform is Red Hat Enterprise Linux 5, but the techniques apply to Fedora Core 6 and higher.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">SETTING UP YOUR DEVELOPMENT SYSTEM</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">I will assume you are building a new ramdisk image for the same architecture as your workstation. If you are not, you will need to explore other means of building the anaconda SRPM. You must build on the target architecture.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">First, set up RPM to build locally:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> mkdir -p ~/rpmbuild/RPMS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> mkdir -p ~/rpmbuild/SRPMS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> mkdir -p ~/rpmbuild/SOURCES</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> mkdir -p ~/rpmbuild/BUILD</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> mkdir -p ~/rpmbuild/SPECS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Next, obtain the anaconda source RPM from the RHEL-5 media and install it. You should not be doing this as root:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> rpm -Uvh anaconda-11.1.2.36-1.src.rpm</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Now you are ready to patch anaconda to your liking.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">PATCHING ANACONDA'S STAGE 1 COMPONENTS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Extract the source:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~/rpmbuild/SPECS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> rpmbuild -bp anaconda.spec</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">RPM may complain about missing dependencies. Install them if you lack them. Anaconda needs a lot of stuff in order to compile.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Patch the source:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~/rpmbuild/BUILD/anaconda-11.1.2.36</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">The stage 1 sources are located in the loader2 subdirectory. The stage 1 components also link against libisys which is in the isys subdirectory. Either way, you will want to make patches against this source tree and put the patches in the ~/rpmbuild/SOURCES directory. For this example, we are patching loader2/loader.c:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">cd loader2</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cp -a loader.c loader.c.orig</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> vim loader.c</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> # la la la...making my changes.... :wq</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~/rpmbuild/BUILD</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> gendiff anaconda-11.1.2.36/ .orig > ~/rpmbuild/SOURCES/anaconda.patch</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Now go and edit ~/rpmbuild/SPECS/anaconda.spec and add anaconda.patch as a patch and make sure it's applied in the %prep section after the %setup macro is run.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">BUILDING A PATCHED ANACONDA</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Simple, use rpmbuild:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~/rpmbuild/SPECS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> rpmbuild -ba anaconda.spec</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">The resulting packages will be written to ~/rpmbuild/RPMS</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">BUILDING A NEW RAMDISK</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">First, we need to get the two stage 1 components that matter: loader and init.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~/rpmbuild/RPMS/</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> rpmdev-extract anaconda-runtime-11.1.2.36-1.i386.rpm</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd anaconda-runtime-11.1.2.36-1</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cp -a usr/lib/anaconda-runtime/loader/init ~/init</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cp -a usr/lib/anaconda-runtime/loader/loader ~/loader</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Second, get the ramdisk image that you want to update. For this example, I am updating the pxeboot/initrd.img from the RHEL-5 tree. I have copied the initrd.img file to my home directory:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> mkdir tmp-initrd</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd tmp-initrd</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> gzip -dc ~/initrd.img | cpio -id</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cat ~/init > sbin/init</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cat ~/loader > sbin/loader</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> (find . | cpio -c -o | gzip -9) > ~/initrd.img</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"> cd ~</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Now the initrd.img file in my home directory contains the new loader and init binaries. Copying this to the boot server and you are ready to go with a new initrd.img for RHEL-5.</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: bold; text-decoration: none; vertical-align: baseline;">CREATING AN INSTALLATION BOOT CD-ROM WITH YOUR NEW initrd.img</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">isolinux (not available for Itanium systems, you'll need to use a loop back mount of the ia64 boot.iso) is used for booting the Red Hat Enterprise Linux installation CD. To create your own CD-ROM to boot the installation program, use the following instructions:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Copy the isolinux/ directory from the Red Hat Enterprise Linux CD #1 into a temporary directory (referred to here as path-to-workspace) using the following command:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">cp -r path-to-cd/isolinux/ path-to-workspace</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Change directories to the path-to-workspace directory you have created:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">cd path-to-work-space</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Copy the new initrd.img to path-to-workspace</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">cp ~/initd.img path-to-workspace/isolinux/</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Make sure the file(s) you have copied have appropriate permissions:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">chmod u+w isolinux/*</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">Finally, issue the following command to create the ISO image file:</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">mkisofs -o file.iso -b isolinux.bin -c boot.cat -no-emul-boot \\</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;">-boot-load-size 4 -boot-info-table -R -J -v -T isolinux/</span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span><br />
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline;"></span></div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-37829239184464971032011-03-22T10:53:00.000-07:002011-03-22T10:53:34.409-07:00Discover Machine info connected to N/W using Nmap Linux tool<div dir="ltr" style="text-align: left;" trbidi="on">#! /bin/bash<br />
<br />
ETHERNET=eth0<br />
<br />
HostList=(`arp -vni $ETHERNET |cut -d " " -f 1 |grep -r 192 |xargs`) <br />
<br />
for (( i = 0 ; i <= ${#HostList[*]} ; i++ ))<br />
do <br />
#nmap ${HostList[i]} <br />
#nmap -O --system-dns ${HostList[i]} <br />
#nmap -O --osscan-guess --system-dns ${HostList[i]} <br />
nmap -F -O -o2 --osscan-limit -oX ${HostList[i]}_$i.xml ${HostList[i]} <br />
done<br />
<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-4286970184426173152011-03-22T10:48:00.001-07:002011-03-22T10:48:49.326-07:00Linux add User passwd without prompting for password<div dir="ltr" style="text-align: left;" trbidi="on">Much simpler : <br />
<br />
echo "passwd " | /usr/bin/passwd --stdin "username"<br />
<br />
<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-16348904297394997102011-03-22T10:45:00.000-07:002011-03-22T10:45:26.100-07:00Squid Proxy Blacklist Auto Update Shell Script<div dir="ltr" style="text-align: left;" trbidi="on"><b>Do necessary changes for path rest is self explanatory :</b> <br />
<br />
cat Update_Blacklists <br />
<br />
#! /bin/bash<br />
if [ -d "/usr/local/squid/share/squidGuard" ] ;then <br />
<br />
cd /usr/local/squid/share/squidGuard/<br />
rm -f -f bl.tar.gz<br />
mv /usr/local/squid/share/squidGuard/db/blacklists /usr/local/squid/share/squidGuard/db/blacklists.old <br />
wget -O bl.tar.gz http://ftp.tdcnorge.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz<br />
<br />
tar --ungzip --extract --exclude=*.diff --directory=/usr/local/squid/share/squidGuard/db --verbose -f bl.tar.gz<br />
<br />
rm -f -f bl.tar.gz<br />
<br />
wget -O bl.tar.gz ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz<br />
<br />
tar --ungzip --extract --exclude=*.diff --directory=/usr/local/squid/share/squidGuard/db --verbose -f bl.tar.gz<br />
<br />
rm -f -f bl.tar.gz<br />
<br />
chown -R squid:squid /usr/local/squid/share/squidGuard/db<br />
<br />
find /usr/local/squid/share/squidGuard/db |xargs chmod 755<br />
rm -rf /usr/local/squid/share/squidGuard/db/blacklists/global_usage <br />
rm -rf /usr/local/squid/share/squidGuard/db/blacklists/README <br />
<br />
else<br />
echo "Error squid may not be Installed "<br />
<br />
fi <br />
<br />
list_of_f=(`ls /usr/local/squid/share/squidGuard/db/blacklists`)<br />
for (( i = 0 ; i < ${#list_of_f[*]}; i++ ))<br />
do<br />
serch=`ls /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} |grep -w urls`<br />
if [ "$serch" == "" ]; then<br />
<br />
echo " /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} : urls not present "<br />
echo " So adding it : `touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/urls && echo "warex.com" >touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/urls`"<br />
else<br />
echo "hi $serch"<br />
fi<br />
<br />
serch1=`ls /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} |grep -w domains`<br />
if [ "$serch1" == "" ]; then<br />
<br />
echo " /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]} : domains not present "<br />
echo " So adding it : `touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/domains && echo " So adding it : `touch /usr/local/squid/share/squidGuard/db/blacklists/${list_of_f[i]}/domains`"`"<br />
else<br />
echo "hi $serch1"<br />
fi<br />
<br />
<br />
done<br />
chown -R squid:squid /usr/local/squid/share/squidGuard/db/*<br />
<br />
find /usr/local/squid/share/squidGuard/db/blacklists |xargs chmod 755<br />
rm -rf /usr/local/squid/share/squidGuard/db/blacklists/global_usage<br />
rm -rf /usr/local/squid/share/squidGuard/db/blacklists/README<br />
<br />
chmod 755 /usr/local/squid/share/squidGuard/squidGuard.conf<br />
<br />
chmod -R 777 /usr/local/squid/share/squidGuard/db/blacklists<br />
<br />
chmod -R 777 /usr/local/squid/share/squidGuard/log<br />
<br />
#ind /usr/local/squid/share/squidGuard/db/blacklists -type d -exec chmod 755 \{\} \; -print<br />
<br />
chmod 777 /usr/local/squid/share/squidGuard/log<br />
<br />
<br />
Best Regards<br />
<br />
ChetanM</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com1tag:blogger.com,1999:blog-4731921270860568870.post-52224994717781643532011-03-22T10:42:00.000-07:002011-03-22T10:42:15.682-07:00Block Commonly Used Torrent on Linux Getway<div dir="ltr" style="text-align: left;" trbidi="on"><b>#! /bin/bash </b><br />
<br />
<br />
iptables -I FORWARD -i eth0 -p tcp --syn --dport 1: -m connlimit --connlimit-above 25 -j REJECT<br />
iptables -I FORWARD -i eth0 -p tcp --syn --dport 1024: -m connlimit --connlimit-above 5 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --dport 1: -m connlimit --connlimit-above 25 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --dport 1024: -m connlimit --connlimit-above 5 -j REJECT<br />
<br />
<b># filter out bad/corrupted p2p traffic</b><br />
<br />
iptables -I PREROUTING -t mangle -m conntrack --ctstate INVALID -j DROP<br />
<br />
<b># block Blobster and Piolet from downloading the initial peer list</b><br />
<br />
iptables -I FORWARD -i eth0 -p tcp --dport 80 -d 128.121.0.0/16 -j REJECT<br />
<br />
<b># and then to block the specific apps :</b><br />
<br />
<b> # block eDonkey</b><br />
<br />
iptables -I FORWARD -i eth0 -p tcp --dport 4662 -j REJECT<br />
iptables -I FORWARD -i eth0 -p tcp --sport 4662 -j REJECT<br />
<br />
<b># block Limewire, Morpheus, Bearshare</b><br />
<br />
iptables -I FORWARD -i eth0 -p tcp --dport 6346:6347 -j REJECT<br />
iptables -I FORWARD -i eth0 -p tcp --sport 6346:6347 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --dport 6346:6347 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --sport 6346:6347 -j REJECT<br />
<br />
<b># block eMule</b><br />
<br />
iptables -I FORWARD -i eth0 -p udp --dport 4672 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --sport 4672 -j REJECT<br />
<br />
<b># block BitTorrent</b><br />
<br />
iptables -I FORWARD -i eth0 -p tcp --dport 6881:6889 -j REJECT<br />
iptables -I FORWARD -i eth0 -p tcp --sport 6881:6889 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --dport 6881:6889 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --sport 6881:6889 -j REJECT<br />
<br />
<b># block WinMx</b><br />
<br />
iptables -I FORWARD -i eth0 -p tcp --dport 6699 -j REJECT<br />
iptables -I FORWARD -i eth0 -p tcp --sport 6699 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --dport 6699 -j REJECT<br />
iptables -I FORWARD -i eth0 -p udp --sport 6699 -j REJECT<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-84425458849797747322011-03-22T10:38:00.000-07:002011-03-22T10:38:51.608-07:00Command Line File Based Network Devices Settings<div dir="ltr" style="text-align: left;" trbidi="on"><b>Step 1. : get N/W config data.</b><br />
<br />
#! /bin/bash<br />
<br />
system-config-network-cmd -d >net_device_data.txt<br />
<br />
<b>Step 2. : Edit the file with required changes</b><br />
<br />
cat net_device_data.txt<br />
<br />
DeviceList.Ethernet.eth0.AutoDNS=true<br />
DeviceList.Ethernet.eth0.HardwareAddress=00:08:a1:ee:63:18<br />
DeviceList.Ethernet.eth0.Type=Ethernet<br />
DeviceList.Ethernet.eth0.IPv6Init=false<br />
DeviceList.Ethernet.eth0.Netmask=255.255.255.0<br />
DeviceList.Ethernet.eth0.BootProto=none<br />
DeviceList.Ethernet.eth0.Device=eth0<br />
DeviceList.Ethernet.eth0.OnBoot=true<br />
DeviceList.Ethernet.eth0.IP=192.168.1.63<br />
DeviceList.Ethernet.eth0.DeviceId=eth0<br />
DeviceList.Ethernet.eth0.AllowUser=false<br />
DeviceList.Ethernet.eth0.Gateway=192.168.3.63<br />
DeviceList.Ethernet.eth1.HardwareAddress=00:e0:4c:D9:0a:c6<br />
DeviceList.Ethernet.eth1.Type=Ethernet<br />
DeviceList.Ethernet.eth1.IPv6Init=false<br />
DeviceList.Ethernet.eth1.Netmask=255.255.255.240<br />
DeviceList.Ethernet.eth1.BootProto=none<br />
DeviceList.Ethernet.eth1.Device=eth1<br />
DeviceList.Ethernet.eth1.OnBoot=true<br />
DeviceList.Ethernet.eth1.IP=15.1.5.179<br />
DeviceList.Ethernet.eth1.DeviceId=eth1<br />
DeviceList.Ethernet.eth1.AllowUser=false<br />
DeviceList.Ethernet.eth1.Gateway=15.1.5.177<br />
<br />
Update N/W details .<br />
<br />
<br />
<b>Step3 .: update the new changes</b><br />
<br />
<br />
#! /bin/bash<br />
<br />
system-config-network-cmd -i -f net_device_data_save.txt<br />
<br />
<br />
<b>Result : helpfull for N/W setting with any web user interface .</b><br />
<br />
<br />
<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-82838191619298151462011-03-22T10:30:00.000-07:002011-03-22T10:30:21.798-07:00Play Active Directory Ntlm Auth With Users and Group Web Integration.<div dir="ltr" style="text-align: left;" trbidi="on">#! /bin/bash<br />
<br />
check_group_ads()<br />
{<br />
echo "">/tmp/glist$$$<br />
arr=(`echo $*`)<br />
IFS=$'\n'<br />
arr=(`wbinfo -g`) <br />
for (( i = 0 ; i < ${#arr[*]}; i++ ))<br />
do <br />
check="`wbinfo -n "${arr[i]}"| grep -w 'Group'`" <br />
if [ "$check" == "" ] ;then <br />
echo "NA" >>/tmp/glist$$$<br />
else<br />
wbinfo -n ${arr[i]} |xargs |cut -d " " -f 1 >>/tmp/glist$$$<br />
fi<br />
done <br />
cat /tmp/glist$$$ |xargs >/home/ads/ads_group_check<br />
}<br />
<br />
<br />
gid_cheking()<br />
{<br />
IFS=$' '<br />
echo "">/home/ads/group_gid<br />
garr=(`cat /home/ads/ads_group_check|xargs `)<br />
for (( i = 0 ; i < ${#garr[*]}; i++ ))<br />
do<br />
check="`wbinfo -n "${garr[i]}"| grep -w 'Group'`"<br />
if [ "${garr[i]}" == "NA" ] ;then<br />
echo "" &>/dev/null<br />
else<br />
echo "${arr[i]} =>" >>/home/ads/group_gid<br />
wbinfo -Y "${garr[i]}" >>/home/ads/group_gid<br />
echo ";" >>/home/ads/group_gid<br />
fi<br />
done<br />
cat /home/ads/group_gid |xargs > /home/ads/group_gid_details<br />
}<br />
<br />
user_gid_checking()<br />
{<br />
echo "">/home/ads/user_gid<br />
ugc=(`wbinfo -u|xargs`)<br />
for (( i = 0 ; i < ${#ugc[*]}; i++ ))<br />
do<br />
echo "${ugc[i]} =>" >>/home/ads/user_gid<br />
#wbinfo -r "${ugc[i]}" |xargs >>/home/ads/user_gid<br />
wbinfo -r "${ugc[i]}" |xargs |cut -d " " -f 2-100 >>/home/ads/user_gid<br />
echo ";" >>/home/ads/user_gid<br />
<br />
<br />
done<br />
cat /home/ads/user_gid |xargs >/home/ads/user_gid_details<br />
}<br />
<br />
<br />
check_group_ads $* &>/dev/null<br />
check_group_ads<br />
gid_cheking <br />
user_gid_checking<br />
<br />
============================<br />
<br />
The Result Is Simple files contaning #array type entrys with user / group id for furter process with databased backed application .<br />
<br />
</div>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-2521944056944827332010-12-29T02:29:00.000-08:002010-12-29T02:29:51.398-08:00Run Rails2.x and Rails3 Application with Passenger under RVM Ruby Environment .Create Add this in config/setup_load_paths.rb<br />
<br />
<br />
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')<br />
begin<br />
#puts ENV['MY_RUBY_HOME']<br />
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))<br />
rvm_lib_path = File.join(rvm_path, 'lib')<br />
$LOAD_PATH.unshift rvm_lib_path<br />
require 'rvm'<br />
RVM.use_from_path! File.dirname(File.dirname(__FILE__))<br />
rescue LoadError<br />
# RVM is unavailable at this point.<br />
raise "RVM ruby lib is currently unavailable."<br />
end<br />
end<br />
<br />
<br />
Specify The rvm ruby under application virtualhost .<br />
<br />
e.g:<br />
<br />
LoadModule passenger_module /home/deploy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.2/ext/apache2/mod_passenger.so<br />
PassengerRoot /home/deploy/.rvm/gems/ruby-1.9.2-p0/gems/passenger-3.0.2<br />
PassengerRuby /home/deploy/.rvm/environments/ruby-1.9.2-p0<br />
<br />
<br />
All done :<br />
<br />
<br />
Run apache under sudo'er from user which is set with RVM environment.chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-86956691289808664752010-12-24T14:01:00.000-08:002010-12-24T14:01:17.315-08:00Clamav Getway Antivirus c-icap Setting For squid.conficap_enable on <br />
icap_preview_enable on <br />
icap_preview_size 128 <br />
icap_send_client_ip on <br />
icap_service service_avi_req reqmod_precache 0 icap://localhost:1344/srv_clamav <br />
icap_service service_avi respmod_precache 1 icap://localhost:1344/srv_clamav <br />
icap_class class_antivirus service_avi service_avi_req <br />
icap_access class_antivirus allow allchetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-50554659869166940412010-12-24T13:59:00.000-08:002010-12-24T13:59:06.873-08:00Nmap To Discover Network IP,Openport,OS Type IN XML Format#! /bin/bash<br />
<br />
ETHERNET=eth0<br />
<br />
HostList=(`arp -vni $ETHERNET |cut -d " " -f 1 |grep -r 192 |xargs`) <br />
<br />
for (( i = 0 ; i <= ${#HostList[*]} ; i++ ))<br />
do <br />
nmap -F -O -o2 --osscan-limit -oX ${HostList[i]}_$i.xml ${HostList[i]} <br />
donechetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-63358257065894780922010-12-24T13:56:00.000-08:002010-12-24T13:56:18.783-08:00Bandwidthd CDF File Processing#! /bin/bash<br />
<br />
user_array=`cat log.*.cdf |cut -d , -f 1 |sort -u |xargs`<br />
<br />
for B in $user_array<br />
do <br />
c=2<br />
<br />
echo -e "For the IP $B"<br />
echo "" > /tmp/port$$$<br />
while [ $c -le 16 ]<br />
do<br />
cat log.*.cdf |grep $B |cut -d , -f $c |xargs >/tmp/ele$$$<br />
I=0<br />
for N in `cat /tmp/ele$$$`<br />
do<br />
I=`expr $I + $N`<br />
done<br />
echo $I >>/tmp/port$$$<br />
(( c++ ))<br />
done<br />
sleep 2<br />
echo -e "\t `cat /tmp/port$$$ |xargs`"<br />
done<br />
rm -rf *.cdf<br />
/etc/init.d/bandwidthd restartchetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-15522481225405339172010-12-24T13:53:00.000-08:002010-12-24T13:53:55.159-08:00How To Keep Track On Disk Usage @Linux#! /bin/bash<br />
# chetan.muneshwar@gmail.com<br />
# script to get disk space status on multiple instances and alert Admin<br />
<br />
<br />
bulk_data=(`df -Ph | grep -r '/' | awk '{ printf "%s-%s-%s-%s ",$3,$4,$5,$6 }'`)<br />
<br />
for (( i = 0 ; i < ${#bulk_data[*]}; i++ ))<br />
do<br />
threshold="`echo ${bulk_data[i]}|cut -d "-" -f 3|cut -d "%" -f 1` "<br />
<br />
<br />
if [ $threshold -le 0 ] ; then<br />
shm_val="`echo ${bulk_data[i]}|grep -r 'shm'`"<br />
if [ "$shm_val" == "" ] ; then<br />
echo "SERVER ${bulk_data[i]} " | mail -s " Disk vol fuLL ISHY-SERVER " chetan.muneshwar@labs.net -c shrikant.lokhande@labs.net<br />
else<br />
echo ""<br />
fi<br />
else<br />
if [ $threshold -le 90 ] ;then<br />
echo ""<br />
else<br />
echo "SERVER ${bulk_data[i]} " | mail -s " Disk vol warning ISHY-SERVER " chetan.muneshwar@labs.net -c shrikant.lokhande@labs.net<br />
fi<br />
fi<br />
done<br />
Finally add cronjob : * * * * * /usr/bin/DISKchetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-59292436725412725242010-11-01T10:37:00.000-07:002010-11-01T10:37:04.072-07:00Anaconda Installer With Custom Brand/Product nameMount stage2.img from iso .<br />
<br />
edit <b>mount_root</b>/usr/lib/anaconda/product.py<br />
<br />
comment the line as below save rebuild stage2.img<br />
<br />
<div style="color: #666666;">[root@localhost anaconda]# cat product.py<br />
#<br />
# product.py: product identification string<br />
#<br />
<br />
import os<br />
<br />
#if os.access("/tmp/product/.buildstamp", os.R_OK):<br />
# path = "/tmp/product/.buildstamp"<br />
#elif os.access("/.buildstamp", os.R_OK):<br />
# path = "/.buildstamp"<br />
#elif os.environ.has_key("PRODBUILDPATH") and \<br />
# os.access(os.environ["PRODBUILDPATH"], os.R_OK):<br />
# path = os.environ["PRODBUILDPATH"]<br />
#else:<br />
# path = None<br />
<br />
productStamp = ""<br />
productName = "SimpleWall"<br />
productVersion = "bluesky"<br />
productPath = "CentOS"<br />
bugUrl = "Cnetos bugy."<br />
<br />
#if path is not None:<br />
# f = open(path, "r")<br />
# lines = f.readlines()<br />
# if len(lines) >= 3:<br />
# productStamp = lines[0][:-1]<br />
# productName = lines[1][:-1]<br />
# productVersion = lines[2][:-1]<br />
# if len(lines) >= 4:<br />
# productPath = lines[3][:-1]<br />
# if len(lines) >= 5:<br />
# bugUrl = lines[4][:-1]<br />
<br />
#if os.environ.has_key("ANACONDA_PRODUCTNAME"):<br />
# productName = os.environ["ANACONDA_PRODUCTNAME"]<br />
#if os.environ.has_key("ANACONDA_PRODUCTVERSION"):<br />
# productVersion = os.environ["ANACONDA_PRODUCTVERSION"]<br />
#if os.environ.has_key("ANACONDA_PRODUCTPATH"):<br />
# productPath = os.environ["ANACONDA_PRODUCTPATH"]<br />
#if os.environ.has_key("ANACONDA_BUGURL"):<br />
# bugUrl = os.environ["ANACONDA_BUGURL"]<br />
</div><br />
Thats it in short .chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-54836640447067540032010-11-01T10:15:00.000-07:002010-11-01T10:15:33.227-07:00How To Connect To Mysql With SSH tunnelRemote connection of mysql is always pain for security concern ssh tunnel is best option .<br />
<br />
<br />
#! /bin/bash<br />
# Copy This script to /usr/bin/<br />
<br />
Tunnel_check="`sudo netstat -tulnp 3307 |grep 127.0.0.1:3307`"<br />
<br />
if [ "$Tunnel_check" == "" ] ;then<br />
echo "Tunnel is really Running ?"<br />
/usr/bin/ssh -2 -f -C -N deploy@ec2-23.45.124.compute-1.amazonaws.com -L 3307/127.0.0.1/3306<br />
else<br />
echo "Tunnel is Running"<br />
fichetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-29566424010542434632010-10-20T06:25:00.000-07:002010-10-20T06:27:13.090-07:00Schedule Scripts With Interval of One Second<b>Cron jobs with default setting has default scheduling time Of 1MIN.</b><br />
Below is the trick to operate in seconds.<br />
#! /bin/bash <br />
PROCNAME=’/usr/bin/xyz.rb’<br />
PIDS=`ps -efa | grep $PROCNAME | grep -v grep | awk ‘{ print $2 }’`<br />
for ff in $PIDS<br />
do<br />
echo “$ff” > /tmp/w<br />
done<br />
if [ -f "/tmp/w" ] ; then<br />
pid=$(cat /tmp/w)<br />
if [ "$pid" == "" ] ;then<br />
/usr/local/bin/ruby /usr/bin/xyz.rb<br />
else<br />
echo “Already running $pid”<br />
fi<br />
rm -rf /tmp/w<br />
else<br />
/usr/local/bin/ruby /usr/bin/xyz.rb &<br />
fi<br />
<b>Where xyz.rb is simple rb program in loop </b><br />
require ‘rubygems’<br />
require ‘daemons’<br />
loop do<br />
system(‘/usr/bin/Server_get |xargs >/var/www/html/text.txt’)<br />
system(‘/usr/bin/get_app_stats |xargs >/var/www/html/app_stat.txt’)<br />
sleep (25)<br />
end<br />
At the last add it to crontab<br />
* * * * * /usr/bin/fast_cron<br />
cheers its much useful in fast messaging,emailing campaigns .chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-19780422133703176132010-10-07T00:20:00.000-07:002010-10-07T00:35:55.265-07:00Caching and Forward name server on linuxacl trusted {<br /> 192.168.0.0/24;<br /> localhost;<br />};<br /><br />options {<br /><br /> directory "/var/named";<br /> dump-file "/var/named/data/cache_dump.db";<br /> statistics-file "/var/named/data/named_stats.txt";<br /> memstatistics-file "/var/named/data/named_mem_stats.txt";<br /><br />forwarders {8.8.8.8;8.8.4.4};<br /> listen-on port 53 { any; };<br /> allow-query { trusted; };<br /> allow-query-cache { trusted; };<br />};<br />logging {<br /> channel default_debug {<br /> file "data/named.run";<br /> severity dynamic;<br /> };<br />};<br />view localhost_resolver {<br /> match-clients { trusted; };<br /> match-destinations { trusted; };<br /> recursion yes;<br /> include "/etc/named.rfc1912.zones";<br />};chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-54758568761189304662010-10-07T00:15:00.000-07:002010-10-07T00:19:57.250-07:00Git Manual clone and push<span style="font-weight: bold;">For github:<br /><br /></span><span style="font-size:100%;"><span style="font-size:85%;">git clone --bare git@github.com:myaccount/my-old-repo.git</span><br /></span><pre class="terminal"><span style="font-size:100%;">cd my-old-repo<br />git push --mirror git@github.com:mycompany/our-new-repo.git<br />cd ..<br />rm -rf my-old-repo<br /><br /><span style="font-weight: bold;">Same can be applicable to private git using gitosis.</span></span><br /><br /><br /></pre>chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-75591367986104599032010-10-04T04:38:00.000-07:002010-10-04T04:42:22.053-07:00Use Memcache As Seesion Store in Rails<span style="font-weight: bold;">Install memcache :</span><br /><br />yum install memcached .<br /><br />chkconfig memcached on<br /><br />/etc/init.d/memcached restart<br /><br /><span style="font-weight: bold;">Install gem : </span><br />gem install memcache-client<br /><br /><span style="font-weight: bold;">Add in environment.rb :</span><br /><br />require 'memcache'<br />CACHE = MemCache.new(:namespace => "myapp)<br />CACHE.servers = '127.0.0.1:11211'<br />config.action_controller.session_store = :mem_cache_store<br /><br />config.action_controller.session = {<br />:session_key => '_my_session',<br />:secret => '9abfc85851505e1a08sdfgsdfgsfdsfdgdsfgbb389be2acd0356ae0d4ea383f59cde7140ec7b04df473c31e1d4a4b9b78d55175d0c37bb29852c025d491c5cda9194ae',<br />:cache => CACHE,<br />:expires=>900 }<br /><br />Note :<br />secret => do rake secret and paste the key .<br />port => default port is 11211chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-19974040355732914902010-10-04T03:55:00.000-07:002010-10-04T04:37:38.963-07:00Clear Session From Database In Ruby On Rails<span style="font-weight: bold;">Create: </span><span> app/models/session.rb</span><br /><br />Session = CGI::Session::ActiveRecordStore::Session<br /> Session.class_eval do<br /> def self.sweep!<br /> delete_all ['updated_at < ?', 15.minutes.ago.utc] <br /> end <span style="font-weight: bold;"><br /><br />Add One cron jobs and swap scheduled :</span><br /><br />1 4 * * * /usr/local/bin/ruby /app/apps/current/script/runner -e production Session.sweep!chetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-70361029158833581182010-09-13T00:20:00.000-07:002010-09-13T00:43:14.640-07:00How To Deploy Application To Remote Server Using Chef-Solo From Local MachineHello Guys<br /><br />Since chef-solo never uses chef server as storage for cookbook , it needs all resources on the machine where deployment has to be done. below is the simple ruby code by which we can fulfill dependency of chef-solo and deploy remote server easily :<br /><br /><span style="font-weight: bold;"></span><span style="font-weight: bold;"></span><span style="font-weight: bold;">chef_deploy.rb :</span><br />#!/usr/bin/env ruby<br /><br />require 'rubygems'<br />require 'net/ssh'<br />require 'net/scp'<br />require 'net/sftp'<br /><br />$CONF_FILE_NAME = ARGV[0]<br /><br />require 'yaml'<br />class AutoDeploy<br /> attr_accessor :ip, :pass, :uname, :filename , :remote_webapps_path , :run_program ,:mod_name<br /><br /> def initialize(config_name)<br /> @config_name = config_name<br /> end<br /><br /> def read_config<br /> config = YAML.load_file("#{@config_name}")<br /> @uname = config["config"]["uname"]<br /> @ip = config["config"]["ip"]<br /> @pass = config["config"]["pass"]<br /> @filename = config["config"]["filename"]<br /> @mod_name = config["config"]["mod_name"]<br /> @run_program = config["config"]["run_program"]<br /> @remote_webapps_path= config["config"]["remote_webapps_path"]<br /> end<br /><br />def run_ruby<br /> Net::SSH.start("#{@ip}", "#{@uname}", :password => "#{@pass}" ) do |ssh|<br /> rest = ssh.exec("#{@run_program}")<br /> end<br />end<br /><br /><br /><br /><br />def do_scp_tasks<br /> Net::SCP.start("#{@ip}", "#{@uname}", :password => "#{@pass}" ) do |scp|<br /> scp.upload!( "#{@filename}" , "#{@remote_webapps_path}" , :recursive => true )<br /> end<br /> end<br />end<br /><br />deploy = AutoDeploy.new($CONF_FILE_NAME)<br />deploy.read_config<br />@git_var = deploy.mod_name<br />puts deploy.mod_name<br />deploy.do_scp_tasks<br />puts "[INFO] chef_resources copy done successfully"<br />deploy.run_ruby<br />puts "[INFO] chef done successfully"<br /><br /><span style="font-weight: bold;">app_details.yml :</span><br />config:<br />mod_name: _deploy<br />uname: root<br />ip: 113.213.216.148<br />pass: aap-stagiwwwneegV1ce<br />filename: programs/chef-101.tar.gz<br />remote_webapps_path: /opt<br />run_program: "cd /opt/ && tar -zxvf chef-101.tar.gz && cd /opt/chef-101/ && chef-solo -l debug -c config/solo.rb -j config/dna.json"<br /><br />1. create direcory<br /><br />mkdir /opt/chef_me/ and save above two files :<br /><br />ls /opt/chef_me/<br /><br /><span style="font-weight: bold;">chef_deploy.rb app_details.yml programs/</span><br /><br />2 . programs folder which contains compressed tar of your solo recipes .<br /><br /><br />3 . call program : ruby chef_deploy.rb app_details.ymlchetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-15890936114219484892010-09-03T09:00:00.000-07:002010-09-03T09:06:17.389-07:00How To Lock Cron Job From Overruning In LinuxJust donwload http://www.unixwiz.net/tools/lockrun.c<br /><br /># compile it<br />$ gcc lockrun.c -o lockrun<br />$ sudo cp lockrun /usr/bin/<br /><br /># add to cron job e.g in single line<br /><br />*/5 * * * * /usr/bin/lockrun --lockfile=/var/run/mcron.lockrun -- /usr/bin /mcron.sh<br /><br /># -- before name of cronjob is necessarychetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0tag:blogger.com,1999:blog-4731921270860568870.post-77861397151083087422010-09-03T00:50:00.001-07:002010-09-03T04:53:17.370-07:00Extra Password Authetication Along With Dialog In Shell Script in Linux#! /bin/bash<br /><br />flash_box() {<br />dialog --infobox $1 5 50<br />sleep .1<br />}<br /><br /><br />console_login()<br />{<br />data=/tmp/_dta$$$<br /><br /># trap it<br />trap "rm -f $data" 0 1 2 5 15<br /><br /># get password<br />dialog --title "Password" \<br />--clear \<br />--insecure \<br />--passwordbox "Enter your password" 10 30 2> $data<br /><br />ret=$?<br /><br /># make decision<br />case $ret in<br /> 0)<br /> <br /> if [ "$(cat $data)" == "chetanMbetter" ] ;then<br /> rm -rf /tmp/chetu<br /> exec bash<br /> <br /> else<br /> if [ "$(cat $data)" == "" ] ;then<br /> flash_box Password_empty<br /> sleep 2<br /> else<br /> flash_box Invalid_password<br /> sleep 2<br /> fi<br /> touch /tmp/chetu<br /> <br /> fi<br /> ;;<br /> *)<br /> main_menu<br /> ;;<br />esac<br />}<br /><br />console_login<br /><br /># save above script as /usr/bin/anyname.shchetuhttp://www.blogger.com/profile/05916720433775249402noreply@blogger.com0