LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-24-2015, 12:13 AM   #1
redhatwannabe
Member
 
Registered: Dec 2008
Posts: 69

Rep: Reputation: 15
why find command has different outcome


Dear all,

my bash version
Code:
grid@ORAC01:~> bash -version
GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
here's my code

Code:
export CURRENT_USER="$(/usr/bin/whoami)"
export GRID_HOME="/u01/app/11.2.0.4/grid"
export ORACLE_HOME="${GRID_HOME}"

export FIND=/usr/bin/find
export RM=/bin/rm

export DAYS=+30
let "MIN=${DAYS}*24*60"

export NODENAME="$(hostname -s)"
export NODENAME="$(echo $NODENAME | tr '[:upper:]' '[:lower:]')"

export MAXDEPTH=1

export GRID_HOME_LOG_MAIN="${GRID_HOME}/log/${NODENAME}"

export GRID_HOME_LOG_LEVEL_1="srvm"
export GRID_HOME_LOG_LEVEL_1_FP="${GRID_HOME_LOG_MAIN}/${GRID_HOME_LOG_LEVEL_1}"
export FIND_LOC="${GRID_HOME_LOG_LEVEL_1_FP}"
#export FIND_FILE_PATTERN="*.log"
export FIND_FILE_PATTERN="${GRID_HOME_LOG_LEVEL_1}*"
echo "\${FIND_LOC} ${FIND_LOC}"
echo "\${FIND_FILE_PATTERN} ${FIND_FILE_PATTERN}"

#${FIND} "${FIND_LOC}" -maxdepth "${MAXDEPTH}" -name "${FIND_FILE_PATTERN}" -mmin "+${MIN}" -user "${CURRENT_USER}" -exec ${RM} {} \;
#${FIND} "${FIND_LOC}" -name "${FIND_FILE_PATTERN}" -mmin "+${MIN}" -user "${CURRENT_USER}" -exec rm {} \;
${FIND} "${FIND_LOC}" -maxdepth "${MAXDEPTH}" -name "${FIND_FILE_PATTERN}" -mmin "+${MIN}" -user "${CURRENT_USER}" -exec ${RM} {} \;
when I execute

Code:
grid@NODE1:~> ~/scripts/remove_old_log/remove_svrm_log.sh
${FIND_LOC} /u01/app/11.2.0.4/grid/log/node01/srvm
${FIND_FILE_PATTERN} srvm*
/bin/rm: cannot remove `/u01/app/11.2.0.4/grid/log/node01/srvm': Is a directory
when I do a further analysis

Code:
grid@NODE1:~> /usr/bin/find "/u01/app/11.2.0.4/grid/log/node01/srvm" -maxdepth "1" -name "srvm*" -mmin "+43200" -user "grid"
/u01/app/11.2.0.4/grid/log/node01/srvm
grid@NODE1:~> /usr/bin/find "/u01/app/11.2.0.4/grid/log/node01/evmd" -maxdepth "1" -name "evmd*" -mmin "+43200" -user "grid"
grid@NODE1:~>
if you observe the above subdirectory srvm is listed while the subdirectory evmd is not listed.


and both have no files at all

Code:
grid@NODE1:~> ls -l /u01/app/11.2.0.4/grid/log/node01/evmd
total 0
grid@NODE1:~> ls -l /u01/app/11.2.0.4/grid/log/node01/srvm
total 0
why is this so?

many thanks in advance!

Last edited by redhatwannabe; 12-24-2015 at 12:14 AM. Reason: change code
 
Old 12-24-2015, 03:29 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,422

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
What was the desired outcome?

The error message is pretty self explanatory and your 'further analysis' does not indicate what you think should happen.
 
Old 12-24-2015, 05:08 AM   #3
redhatwannabe
Member
 
Registered: Dec 2008
Posts: 69

Original Poster
Rep: Reputation: 15
desired outcome is to delete the files accordingly if there is files that meet the criteria, if don't have then it should not have any error messages.


i.e.


/usr/bin/find "/u01/app/11.2.0.4/grid/log/node01/evmd" -maxdepth "1" -name "evmd*" -mmin "+43200" -user "grid"

should delete /u01/app/11.2.0.4/grid/log/node01/evmd/evmd* files that are 30 days ago and belong to user grid.

like wise

/usr/bin/find "/u01/app/11.2.0.4/grid/log/node01/srvm" -maxdepth "1" -name "srvm*" -mmin "+43200" -user "grid"

should delete /u01/app/11.2.0.4/grid/log/node01/srvm/srvm* that are 30 days ago and belong to user grid.


The error message is pretty self explanatory and your 'further analysis' does not indicate what you think should happen.=>don't get what u mean by self explanatory.

How do u explain the fact that both are empty directories yet one has error and the other don't have when it come to deleting files. In the first place I never intended to delete the directory.
 
Old 12-24-2015, 07:16 AM   #4
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 255

Rep: Reputation: 101Reputation: 101
You want to delete files, and the error is about an attempt to delete a directory => your find needs -type f
--
The other directory is not attempted to delete because it does not meet the criteria: is not old enough or has a wrong owner.
--
Older than 30 days? Your find needs -mtime +30

Last edited by MadeInGermany; 12-24-2015 at 07:22 AM.
 
1 members found this post helpful.
Old 12-24-2015, 09:53 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,422

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
Further to the above, maxdepth will include the directory being searched in, so if you do not set the type as advised and the directory is of the right age and owner, it will be returned an rm will
give you the error message (hence, I thought it was self explanatory).
 
1 members found this post helpful.
Old 12-24-2015, 03:09 PM   #6
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,606

Rep: Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977Reputation: 977
Quote:
Originally Posted by redhatwannabe View Post
Code:
grid@ORAC01:~> bash -version
GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
i just thought i'd point that out.
even on centos 6.7. (the "oldest" still supported distro i can think of) bash is at version 4.1.2.
 
Old 12-28-2015, 03:34 AM   #7
redhatwannabe
Member
 
Registered: Dec 2008
Posts: 69

Original Poster
Rep: Reputation: 15
grail u r dead right
Further to the above, maxdepth will include the directory being searched in, so if you do not set the type as advised and the directory is of the right age and owner, it will be returned an rm will
give you the error message (hence, I thought it was self explanatory).


grid@NODE01:~> ls -ld "/u01/app/11.2.0.4/grid/log/node01/srvm"
drwxr-x--- 2 grid oinstall 4096 Oct 28 13:58 /u01/app/11.2.0.4/grid/log/node01/srvm

because there's no files in this directory hence it was never modified for a very long time.


made in germany thanks a lot u too are also helpful in introducing the additional filter -type f
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A bit worried about outCome of emerge -ca browser Calculate 2 09-11-2014 02:26 AM
mixing sata drives on same system; outcome? plisken Linux - Hardware 7 12-09-2012 06:52 AM
FreeMWare Project Outcome Invisivin Linux - Virtualization and Cloud 4 07-24-2012 08:20 PM
LXer: Alfresco: Open Source Will Have Winner-Take-All Outcome LXer Syndicated Linux News 0 12-16-2009 04:41 PM
Perl wonky IF outcome inside a @list foreach loop OldGaf Programming 3 09-18-2009 11:21 AM


All times are GMT -5. The time now is 01:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration