This is telling you that the value for pday is not set or not an integer, so your command as a whole becomes invalid. Could you sh -xv rmAgingFile.sh file*.log 2 and review the output to see what is actually being run? Do you actually assign the argument 2 to that variable pday ? I presume it would need something like pday="${2}" early in your code to do that.
It might also be that the shell where you are running the command has expanded file*.log to each file it found, so that might mess up the input. You could try by wrapping it in double quotes, so sh -xv rmAgingFile.sh "file*.log" 2 might be better. Obviously drop the -xv if this does the trick.
If this is still failing, could you paste the output/errors showing the expanded find command as it is trying to run?
originally it was written on AIX and is working fine then had to moved the to same script to Linux. basically the goal of the script is to find a file that is days old depending on the parameter.
here is the output using this command sh -xv rmAgingFile.sh file*.log 2
p1=$1
+ p1=file_1.log
pday=$2
+ pday=file_2.log
vdir=`pwd`
pwd
++ pwd
+ vdir=/sbin/scripts
vhomedir=`pwd`
pwd
++ pwd
+ vhomedir=/sbin/scripts
vctr=0
+ vctr=0
# check for null parameter
if [ $# -lt 1 ]; then
echo current directory $vdir
echo no parameter entered
echo
else
#check for directory entry only
if [ -d $p1 ]; then
vdir=$p1
echo current directory $vdir
cd $vdir
echo no file parameter entered
echo
#check for directory entry and file
elif [ -f $p1 ]; then
vdir=`dirname $p1`
echo current directory $vdir
cd $vdir
for f in $1
do
vfile=`basename $f`
#for i in `find $vdir -name "$vfile" -mtime +$pday`
#ommit the subdirectories in the searcch
for i in `find . ! -name . -prune -type f -name "$vfile" -daystart -mtime +$pday`
do
let vctr=$vctr+1
vfile=`basename $i`
echo deleting aging files $vfile
rm $vfile
done
done
if [ $vctr -eq 0 ]; then
echo "no aging files found that are $pday days old"
fi
else
echo $p1 not found
fi
fi
+ '[' 3 -lt 1 ']'
+ '[' -d file_1.log ']'
+ '[' -f file_1.log ']'
dirname $p1
++ dirname file_1.log
+ vdir=.
+ echo current directory .
current directory .
+ cd .
+ for f in '$1'
basename $f
++ basename file_1.log
+ vfile=file_1.log
find . ! -name . -prune -type f -name "$vfile" -daystart -mtime +$pday
++ find . '!' -name . -prune -type f -name file_1.log -daystart -mtime +file_2.log
find: missing argument to `-mtime'
+ '[' 0 -eq 0 ']'
+ echo 'no aging files found that are file_2.log days old'
no aging files found that are file_2.log days old
#return the cursor to the home directory
cd $vhomedir
+ cd /sbin/scripts
# put a white space
echo
+ echo
I replaced the code with this smaller code and it works.
p1=$1
pday=$2
for f in $(ls -1 $p1)
do
vfile=`basename $f`
echo $vfile
for i in `find . ! -name . -prune -type f -name $vfile -daystart -mtime +$pday`
do
let vctr=$vctr+1
vfile=`basename $i`
echo deleting aging files $vfile
rm $vfile
done
if [ $vctr -eq 0 ]; then
echo "no aging files found that are $pday days old"
fi
done
# write a whitespace
echo