Hi,
I have a script to retrieve data files from server and store them in a directory on local disk. The script runs everyday as cron job. But now those files are too many so my boss wants me to put the files into different directories base on dates.
Those files look like this:
FCNCP104500104_SPA_2011-04-08_04-53-56-GMT_P08-00.nar
My original script:
#! /bin/bash
EMC_HOST='3.3.3.3'
EMC_USER='admin'
EMC_PASSWORD='password'
NAV_LOG_FILE='/var/log/naviseccli'
NAVISECCLI='/opt/Navisphere/bin/naviseccli'
NAV_BASE_CMD="${NAVISECCLI} -h ${EMC_HOST} -user ${EMC_USER} -password ${EMC_PASSWORD} -scope 0"
RETRIEVE_DIR='/mnt/emc_data'
#
# Simple logger.
#
log () {
echo ${1} >> ${NAV_LOG_FILE}
}
#
# Retrieve file.
#
retrieve () {
log "Retrieve file ${1}..."
cmd="$NAV_BASE_CMD analyzer -archive -file ${1} -o"
eval $cmd
if [ $? -ne 0 ] ; then
log "$(date): Retrieve $1 failed"
log "command: $cmd"
log "error code: $?"
exit -1
fi
}
#
# List all archives on EMC.
#
list () {
file_list=$($NAV_BASE_CMD analyzer -archive -list | awk 'BEGIN {IGNORECASE=1;} /nar$/ { print $NF }')
if [ $? -ne 0 ] ; then
log "$(date): list archives failed"
log "error code: $?"
exit -2
fi
}
cd $RETRIEVE_DIR || exit -1
list
for f in ${file_list} ; do
[ -f ${f} ] || retrieve ${f}
done
Any suggestions to improve (rewrite) the script?