Archive for the 'General' Category

Top 5 most useful commands or tools for Linux administrators

There are plenty such tools which are definitely very useful for Linux admins. Here I am just trying to figure out 5 of such useful tools which are used by a normal Linux administrator in day to day operations. A tool which I think is most useful may not fit in your usage and its definitely possible that you know some awesome tool which I forgot to include here, for such case, I am requesting hereby to please mention the tool in comments. One more thing, I am mentioning here tools which are somewhat optional and not absolutely required for everybody and excluding tool which have no viable alternative and every Linux admin have to use them.. such as SSH, SCP etc.

Detect directory or file changes in *nix

There are various wasys to do this, but this is what I implemented. It is working as expected as of now on my RHEL 5.x boxes. I’ll take my usecase here and describe things.

Plesk web hosting control panel is managing several hundred domains on one of RHEL box. Addition and removal of domains is very common. We need to sync all domain’s httpdocs directory to other webservers. Of course, a simple rsync can be setup for this but it’s much efficient that rsync should only run when there’s any change, ie addition/removal of a domain or file updation etc. What I mean to say, instead of letting rsync detect changes, its better that our script should detect changes and then run rsync. The obvious advantage is that network burden is reduced because rsync will only sync contents with our servers when there are changes.

Create bootable USB drive with Fedora 11

Here are quick steps on CentOS 5.3 box (should be identical on any RH based distro) to create a bootable USB stick of latest Fedora 11 distrubution:

1. Check whether required tools are already installed or not:

# rpm -q livecd
<no output>

2. Install tools:

# yum install livecd-tools

3. Insert your USB stick in one of USB port, it should get automatically detected and mounted. Make sure your stick has atleast 1 GB free space. Jump to step #7 as it’s absolutely not necessary to format it, but if there’s no worthy data in and you are willing to clean it completely before moving forward, here is the way to proceed after unmounting it:

Install html2ps/pdf library to create PDF files using php

Generating PDF or postscript files on the fly with php is quite easy using a library called html2ps/pdf. Following are the steps which I took to install it on a fedora 7 server running php 5.x

As per the documentation, html2ps/pdf requires either Ghostscript or PDFLIB libraries for fast pdf generation. You can also use the inbuilt FPdf routines but that’s much slower. PDFLIB is non-free library which may requires you to have a license to use, therefore, I opted for GhostScript here.

Step 1. Check whether ghostscript is already installed or not:

Script to sync files between web severs having plesk

I got a little assignment where there are two webservers are there behind a load balancer and both needs to have identical files. Both server has plesk control panel. As we know, plesk store website files in /var/www/vhosts/domain/httpdocs directory, here domain is the name of website. Though this script can be used in any other case, just you may need to update it little bit.

I wrote a wrapper script for rsync and deployed there. Here is the script:

#!/bin/bash
 
############### websync.sh by Jagbir Singh #################
#
# This script acts as wrapper for rsync. It checks every domain listed in /var/www/vshots
# for existence in other server, if found there, then sync domain's 'httpdocs' only directory.
#
# ver 1.0 Mar 8, 2009: Initial version.
#
#############################################################
 
cd /var/www/vhosts
webserver2="192.168.30.2"
 
## get directory list
ls --file-type | grep "\/" | sed 's/\///' | grep -Ev "^chroot|^default" > /tmp/dir.list
exec 10</tmp/dir.list
let count=0
 
## check domains in other server and update them.
while read LINE <&10; do
    ## update second webserver if domain exist there (just in case)
    if  `ssh $webserver2 "ls /var/www/vhosts/$LINE/httpdocs/ > /dev/null 2>&1"` ; then
        `rsync -az --delete -e ssh /var/www/vhosts/$LINE/httpdocs/ $webserver2:/var/www/vhosts/$LINE/httpdocs/`
    fi
 
    ((count++))
done
exec 10>&-
Get Adobe Flash playerPlugin by wpburn.com wordpress themes