Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Problem in compressing and moving files

$
0
0
Hi

I am writing a sample script (sample.ksh) to compress files in the source directory and move them to another directory.
The script takes a config file (files.config) as the paramter the contents of which are as given under:

Code:

/abc/src ${TSTENV}-xxx-yyy~1.log /abc/src/dest
/abc/src ${TSTENV}-yyy~1.log /abc/src/dest
/abc/src ${TSTENV}-zzz~rem_plg~1.log /abc/src/dest

This file consists of three parts:

First is the source directory where the files reside: /abc/src
Second is the files to be compressed: ${TSTENV}-xxx-yyy~1.log, ${TSTENV}-yyy~1.log, ${TSTENV}-zzz~rem_plg~1.log
Third is the destination directory where the files are to be moved post compression: /abc/src/dest

The sample.ksh written so far looks like:

Code:

#!/bin/ksh
INP_PARAM=files.config

[[ ! -f ${INP_PARAM} ]] && echo "File ${INP_PARAM} is not present" && exit 1

DTTM=`date "+%Y%m%d"`

echo "`basename $0` started on `date`"

cat ${INP_PARAM} | \
while read LINE
do
        FIRST_ARG=`echo ${LINE} | cut -d" " -f1`
        WORK_DIR=`eval "echo ${FIRST_ARG}"`
        SECOND_ARG=`echo ${LINE} | cut -d" " -f2`
        FILE_NAME=`eval "echo ${SECOND_ARG}"`
        THIRD_ARG=`echo ${LINE} | cut -d" " -f3`
        ARCHIVE_DIR=`eval "echo ${THIRD_ARG}"`

        [[ ! -d ${ARCHIVE_DIR} ]] && mkdir ${ARCHIVE_DIR}

        cd ${WORK_DIR}

        #Compress the log files
        cut -d " "

        [[cut : -f ${FILE_NAME} ]] && (gzip "${FILE_NAME}"; chmod 644 "${FILE_NAME}".gz) || echo "${FILE_NAME} does not exists"
        [[ $? != 0 ]] && echo "Error: Unable to compress the log file ${FILE_NAME}" && exit 1

        #Move the .gz file to ARCHIVE directory
        [[ -f ${FILE_NAME}.gz ]] && mv "${FILE_NAME}".gz ${ARCHIVE_DIR}/"${FILE_NAME}".${DTTM}.gz || echo "${FILE_NAME} doesn't exists"
        [[ $? != 0 ]] && echo "Error: Unable to move the file ${FILE_NAME}.${DTTM}.gz to ${ARCHIVE_DIR}" && exit 1

        #Create empty log files
        touch ${FILE_NAME}

done

echo "`basename $0` ended on `date`"

exit 0

However, when I try to execute, am getting the following error:
Code:

Usage: cut {-b <list> [-n] | -c <list> | -f <list> [-d <char>] [-s]} file ...
./sample.ksh[27]: [[cut:  not found
mach01-xxx-yyy~1.log does not exists
mach01-xxx-yyy~1.log doesn't exists
Usage: cut {-b <list> [-n] | -c <list> | -f <list> [-d <char>] [-s]} file ...
./sample.ksh[27]: [[cut:  not found
mach01-yyy~1.log mach01-yyy~1.log. mach01-yyy~1.log.15-05-25_20:41:05 mach01-yyy~1.log.15-05-26_20:29:40 mach01-yyy~1.log.15-05-27_20:28:32 mach01-yyy~1.log.15-05-28_20:28:27 does not exists
mach01-yyy~1.log mach01-yyy~1.log. mach01-yyy~1.log.15-05-25_20:41:05 mach01-yyy~1.log.15-05-26_20:29:40 mach01-yyy~1.log.15-05-27_20:28:32 mach01-yyy~1.log.15-05-28_20:28:27 doesn't exists
Usage: cut {-b <list> [-n] | -c <list> | -f <list> [-d <char>] [-s]} file ...
./sample.ksh[27]: [[cut:  not found
mach01-zzz~rem_plg~1.log does not exists
mach01-zzz~rem_plg~1.log doesn't exists

The script isn't recognizing any of the files under the source directory even though they are present there and some of the log files have a date and timestamp extension as seen in the output above which I want to move as well but is not happening.

Any help would be greatly appreciated.

Viewing all articles
Browse latest Browse all 16232