[Solved] Find command is not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Find command is not working
# 1  
Old 01-16-2014
[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:

Code:
/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

Code:
#!/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  
Old 01-16-2014
2>/dev/null is at an unusual place. Try moving it after or before the command.
# 3  
Old 01-16-2014
Quote:
Originally Posted by Scrutinizer
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:

Code:
./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 :/
# 4  
Old 01-16-2014
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!
# 5  
Old 01-16-2014
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.
# 6  
Old 01-16-2014
Quote:
Originally Posted by vbe
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!
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 itSmilie

KR
EAGLE

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

Quote:
Originally Posted by mritusmoi
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.
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

[Solved] Find command hangs my terminal session

Hello every one. I know little to nothing about AIX. Recently I have been assigned to an AIX project. For some reason or another the find command is hanging the server. Well it does not hand server per say, it just freezes my terminal session. after running find, I waited up to 40 min and... (3 Replies)
Discussion started by: busi386
3 Replies

2. Shell Programming and Scripting

Working with FIND command

Hi , In /home/etc/files path ran the following command find . -name 'ABC*' | wc -l The output of the above command is 25 as expected In path /home path ran the following command find . -name '/home/etc/files/ABC*' | wc -l The output of the abvoe command is 0 . Why the above... (3 Replies)
Discussion started by: smile689
3 Replies

3. Shell Programming and Scripting

[Solved] Grep within find command

Platform: AIX 6.1/ksh Question1. I want to grep for the string "CUSTOM_PKMS" in all the files in server except those files with extensions .dbf , .ctl and .dmp I started running the following command but it is taking too long because there are lots of .dbf , .ctl and .dmp files in this... (6 Replies)
Discussion started by: John K
6 Replies

4. UNIX Desktop Questions & Answers

[SOLVED] find command match pattern

Hello, I would like to ask you, how to match directory names. I need to find only directories, which are created only from numbers and doesn't include any letters. I used command find $AC_WORKDIR/work_archive/test/$dirs_years -maxdepth 1 -name \\* -print If I have dirs like 12... (3 Replies)
Discussion started by: satin1321
3 Replies

5. UNIX for Dummies Questions & Answers

[Solved] weird in find -exec command

i feel weird with this 2 command find /tmp/*test* -user `whoami` -mtime +1 -type f -exec rm -f {}\; find /tmp/*test* -user `whoami` -mtime +1 -type f -exec ls -lrt {}\; the first one return correct which only delete those filename that consist *test* where second command it listed all the... (12 Replies)
Discussion started by: lsy
12 Replies

6. Solaris

[Solved] passwd command not working

Hi all, I have got a problem, i have Solaris 8 server, where on running the passwd command, it says permission denied. I have checked /bin/passwd, /etc/passwd, /etc/shadow all have permissions as like one working server. It is happening for root user and all other users. i have tried... (6 Replies)
Discussion started by: varunksharma87
6 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Assistance with find command please

Trying to locate files less than xx days old, throughout all directories/subdirectories, but excluding certain types of directories and files. The directories I want to search all contain the same characteristic (dbdef, pldef, ghdef, etc), and there are subdirectories within that I need to... (2 Replies)
Discussion started by: Condmach
2 Replies

8. Shell Programming and Scripting

find command not working

Hi all, find command not working for me in a perticular directory.The same command is working fine in any other directory. Following is the command i issued: find . -type f -print my question is , is it possbile to disable a command only for a perticular directory ??...of course... (4 Replies)
Discussion started by: panyam
4 Replies

9. UNIX for Dummies Questions & Answers

Find command not working as expected

I have a script with a find command using xargs to copy the files found to another directory. The find command is finding the appropriate file, but it's not copying. I've checked permissions, and those are all O.K., so I'm not sure what I'm missing. Any help is greatly appreciated. This is... (2 Replies)
Discussion started by: mpflug
2 Replies

10. UNIX for Advanced & Expert Users

find command not working

Hi, Having issues with the . parameter in the find command. Issuing "find . -name \*.pl" gives me find: cannot open .: No such device I got it working by substituting . with *, so "find * -name \*.pl" gives the correct listing. bin/test.pl "which find" lists /bin/find. Anybody... (7 Replies)
Discussion started by: jabrady
7 Replies
Login or Register to Ask a Question