I am a newbie in unix shell script programming . After I have tried to execute this code , I found the problem said that "syntax error near unexpected token done" . I don't know that where is the mistake in my code . Could anyone help me out this problem ?, thank you in advance
PS* : I executed it in Redhat Enterprise Linux 4
and this is my code :
#!/bin/ksh
# Purge Script
# Input:
# 1. path (absolute path)
# 2. filename (does not apply to empty folder name)
# 3. retention policy (in day)
# Example:
# /home/oretail/purge.sh /home/oretail/test/ 'file*' 2
if [ $# -ne 3 ]
then
echo "Error: missing parameter!";
echo '{path} {filepatttern} {retentionday}';
echo "Note: Don't forget to enclose {filepattern} in single quote!"
exit 1;
fi
if [ ! -d "$1" ] #if not directory -> $1
then
echo "Error: $1 is not a directory!";
echo $*
exit 1;
fi
path=$1
expr=$2
days=$3
echo `date`
echo "Running purge with path=${path} expr=${expr} days=${days}"
# finding all files match parameters
# note: The -name test comes before the -type test in order to avoid having to call stat(2) on every file.
cmd="find ${path} -mtime +${days} -type f | egrep -i '${expr}'"
#echo "$cmd"
eval $cmd | while read F
do
echo "$F"
rm -f $F
done
# Knot 7-6-2010 (final)