Checking the directory and concatenate the data of all the log files in that dir

Hi Gurus,

I am new to unix and need your help to make a shell script. I have a requirement, would appreciate if you could please help me on it:

Requirement:
-------------

I will pass 2 parameters in shell script 1). Directory name say errors 2). file extension say .log
First of all this script should check whether the specified directory exist or not, if exists then it should return "true" otherwise "false"
If the directory exists then, i want to concatenate the data of all the files (with the extension as passed in the parameter) and return this concatenated data.

Please help.

Thanks,

Regards,
AS

Hi,

After reading a bit i have made this script but not sure how far it is right. Please help.

echo $*
INFILE_DIR=$1
INFILE_EXT=$2
cd $XXIPO_TOP
if test -s $INFILE_DIR/.INFILE_EXT; then
echo " "
echo "
** File Concatenation Started **"
echo " "
for i in `ls -l $INFILE_DIR/
.INFILE_EXT | awk '{print $9}'
do
cat $i >> targetfilename
done

else
echo "*** File to be imported doesnot exist or has no data **"
echo $INFILE_DIR/
.INFILE_EXT
exit 1
fi

Thanks.,
Regards,
AS

this small code will do

if test -d $1 ; then
echo "DIR exist"
cd $1
echo "*** File Concatenation Started ***"
cat *$2>>consolidatefile
else
echo "false"
fi

Thanks for your help Vidyadhar. i will test this script and will let u know if any issue faced.

Thanks alot..

Regards,
AS

Hi Vidyadhar, this script is erroring out saying "fi is not expected". Please suggest.

Thanks,

Regards,
AS