[Solved] Find command is not working

Hello Friends,

I have a problem about a little script,

when i run the following two lines one by one on CLI then they work well:

/usr/bin/mkdir `perl -e 'use POSIX qw(strftime); print strftime "%Y-%m-%d",localtime(time() - 30*24*60*60);'`
find . -type f -name "fuseesb.log.*" -mtime 30 2>/dev/null -exec cp -p "{}" /data/log/so/`perl -e 'use POSIX qw(strftime); print strftime "%Y-%m-%d",localtime(time() - 30*24*60*60);'` ";"

But when i execute the script which is like the following they don't work, i don't see 30 days old files are coppied, any comments? i have tried it hard but could not find the cause of this issue

#!/bin/bash
TDY=`perl -e 'use POSIX qw(strftime); print strftime "%Y-%m-%d",localtime(time() - 30*24*60*60);'`
NAME='fuseesb.log.'
PATH='/data/log/so'
DAY=30
cd $PATH
/usr/bin/mkdir "$TDY"
find $PATH -type f -name "$NAME*" -mtime $DAY 2>/dev/null -exec cp "{}" "$PATH/$TDY" ";"

any help appreciated!

KR,
EAGLE

2>/dev/null is at an unusual place. Try moving it after or before the command.

I have tried it but it did not change,

when i have removed it then it gives the following error msg:

./test.sh: line 10: find: command not found

I don't understand why, all i wanted to do is to make the script a bit generic for log compressing & moving.. I can do it normal way without using variables but anyways i would like to find out what the issue is :confused:

You have made a mess...
You overwrited your PATH env variable and so now it finds no commands since PATH=/data/log/so choose another name for your variable this one is SACRED!

never modify the shell variable PATH.. When required it just should be appended..
eg PATH=$PATH:/{whatever path u want to add}

It seems this is the root cause of your command error.

THanks a lot, i could not realise it, when i checked "env" yes there is PATH as well, that was copy-paste from another script which i could not think twice about it:D

KR
EAGLE

---------- Post updated at 04:26 PM ---------- Previous update was at 02:54 PM ----------

Actually it is coming from a careless copy-paste and i could not realise it,
Like VBE said it really messed everything and it has to be checked before proceeding..