Mass Copy

 

This scripw will copy a master set of data to a multitude of locations. This script, while not dechnically hard was written as more of an example of proper scripting technique.

#!/bin/bash
#### Mass Copy Script
#  Build: 001
#   Date: 12-14-2007
# Author: Steven McGrath

## Configuration Options

# Location of the source data
SOURCE_FOLDER=/var/source

# Location of the base folder for the mass copy.
BASE_FOLDER=/home

# Location of the exclude file.
# NOTE: one entry per line.
EXCLUDE_FILE=/etc/excludeme.conf

## Start Script

# Get the length of the exclude file.
EXCLUDE_LENGTH=$(echo $EXCLUDE_FILE | wc -l)

# Lets build the ignores for the directory listing
# based off of the input from the exclude file.
EXCLUDE_ME=""
for ((i=0;i<=$EXCLUDE_LENGTH;i+=1));do
	EXCLUDE_ME=$EXCLUDE_ME" -I $(cat $EXCLUDE_FILE | head -n $i | tail -n 1)"
			# There has to be a more efficient way to grab a given line
			# however I'm lazy and this is a first build.
done

# Grab the folders that we will be using for the copy.
INCLUDE_ME=$(ls $EXCLUDE_ME $BASE_FOLDER)

# How many entries are in the include variable.
INCLUDE_LENGTH$(echo $INCLUDE_LENGTH | wc -c)

# COPY TIME!!!!
for ((i=0;i<=$INCLUDE_LENGTH;i+=1));do
	cp -R $SOURCE_FOLDER $BASE_FOLDER/$(echo $INCLUDE_ME | cut -d " " -f $i)
done

# Spit out something for the user to make them feel nice.
echo "Mass Copy Complete."