Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 2007 > April 2007

Listing 1 SortingHat

#!/bin/ksh
# Listing 1
# SortingHat
USAGE="Usage: $(basename $0) [-h host] [-bflr] pathname"

SORTINGHAT_DIR=/opt/SortingHat
SERVERS_DIR=$SORTINGHAT_DIR/servers
DEFAULT_DIR=$SORTINGHAT_DIR/default
BACKUP_DIR=$SORTINGHAT_DIR/backup
CURRENT_DIR=$SORTINGHAT_DIR/current

HOST=""
LIST="" 
FIND="" 
BACKUP=""
current_file=""
REPLACE="FALSE"

while getopts bfh:lr option
do
    case "$option"
    in
    b)
        BACKUP="TRUE";;
    f)
        FIND="TRUE" ;;
    h)
        HOST=$OPTARG;;
    l)
        LIST="TRUE";;
    r)
        REPLACE="TRUE";;
    \?)
        exit 1;;
    esac
done

if [ "$OPTIND" -gt "$#" ]
then
    echo $USAGE
    exit 1
else
    shift $(($OPTIND-1))
    file=$1
fi

echo "\n$0..."

if [ -z "$HOST" ]
then
    HOST=$(cat /etc/nodename)
else
    echo "Host: $HOST"
fi

echo "File: $file"

HOST_DIR=$SERVERS_DIR/$HOST

if [ "$FIND" == "TRUE" ]
then
    echo "Searching for $HOST_DIR$file"
    if [ -f $HOST_DIR$file ]
    then
        echo "Found $HOST_DIR$file"
        current_file=$HOST_DIR$file
      else
        echo "Searching for $DEFAULT_DIR$file"
        if [ -f $DEFAULT_DIR$file ]
        then
            echo "Found $DEFAULT_DIR$file"
            current_file=$DEFAULT_DIR$file
        else
            echo "Searching for $file "
            if [ -f $file ]
            then
                echo "Found $file"
                current_file=$file
                  else
                echo "Searching for $BACKUP_DIR$file"
                if [ -f $BACKUP_DIR$file ]
                then
                    echo "Found $BACKUP_DIR$file"
                    current_file=$BACKUP_DIR$file
                fi
            fi
        fi
    fi

    if [ -z "$current_file" ]
    then
        echo "Did not find a current copy of $file"
        rm -f $CURRENT_DIR$file
    else
        if [ ! -d $CURRENT_DIR$(dirname $file) ]
        then
           mkdir -p $CURRENT_DIR$(dirname $file)
        fi
        cp -p $current_file $CURRENT_DIR$file
        echo "Current copy: $CURRENT_DIR$file"
    fi
fi

if [ "$BACKUP" == "TRUE" ]
then
    if [ -f $file ]
    then  
        if [ ! -d $BACKUP_DIR$(dirname $file) ]
        then
          mkdir -p $BACKUP_DIR$(dirname $file)
        fi
        backup_file=$BACKUP_DIR$file.$

				  



MarketPlace

"Six Sigma" Certification
Villanova Six Sigma Certification 100% Online Program - Free Info.

Project Management-Online
Nation's Leading Online PMP Course From Villanova-Find Out More Now.

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Automate Software Builds with Visual Build Pro
Easily create an automated, repeatable process for building and deploying software.

Wanna see your ad here?