Operating System - HP-UX
1834869 Members
2525 Online
110070 Solutions
New Discussion

error: find: cannot get 'pwd'

 
SOLVED
Go to solution
Ratzie
Super Advisor

error: find: cannot get 'pwd'

I have wrote this script that at the beginning does a find and deletes the files, but when I check my mail I get an error, and the files are not deleted. All permissions are set, and my variables are correct...


find $BACKUP_LOGS_DIR -name archbu.log.* -type f -mtime +7 -exec /bin/rm -f {} ";"


##
## Remove archive backup log files in $BACKUP_DEPOT
##
echo ""
echo "Removing previous copies of archlogs in $BACKUP_DEPOT..."
find $BACKUP_DEPOT -name archive_logs.*.bz2 -type f -mtime +7 -exec /bin/rm -f {} ";"
10 REPLIES 10
Pete Randall
Outstanding Contributor

Re: error: find: cannot get 'pwd'

Are you sure the variables $BACKUP_LOGS_DIR and $BACKUP_DEPOT are set? How are you running this script. If it is being run through cron, you'll need to specifically set variables, paths, etc.


Pete

Pete
G. Vrijhoeven
Honored Contributor

Re: error: find: cannot get 'pwd'

HI,

May be a stupid question but in what dir do you start this script.
check pwd before you start/ execute the script.

Gideon
A. Clay Stephenson
Acclaimed Contributor

Re: error: find: cannot get 'pwd'

All of your variables are not correct:

Your problem (assuming all else is correct) is here:


-name archbu.log.*

this should be:
-name 'archbu.log.*'

You need to quote the pattern so that find rather than the shell itself instantiates the wildcarding.



Also replace -f {} ";" with -f {} \;

If it ain't broke, I can fix that.
Ratzie
Super Advisor

Re: error: find: cannot get 'pwd'

It is running thru roots crontab...

0 3 * * 6 su acadmin -c /home/bu/scripts/backup/backup_acdb.sh > /home/bu/log/backup_acdb.log.`date +\%j`

I also set the variables at the beginning of the script...
BACKUP_DEPOT=/opt/app/oracle/oradata/acdb/db5
BACKUP_LOGS_DIR=/home/bu/log
Bill Hassell
Honored Contributor

Re: error: find: cannot get 'pwd'

To avoid spelling errors, always put:

set -u

at the beginning of your script. Then, to actually trace your script, put set -x at the beginning of the script and you'll get a mail message with the trace results. Also, if your script works OK when you run it manually but fails in cron, remember that cron does not login so you don't have the same environment.

Also, it's important to protect any -name expressions so that find will parse the special characters. Put the expression string in single quotes: -name 'archbu.log.*' or -name 'archive_logs.*.bz2'


Bill Hassell, sysadmin
Ratzie
Super Advisor

Re: error: find: cannot get 'pwd'

This is the output from the set -u, set -x
+ find /home/bu/log -name archbu.log.* -type f -mtime +7 -exec /bin/rm -f {} ;
find: cannot get 'pwd'


+ echo
+ echo Removing previous copies of archlogs in /opt/app/oracle/oradata/acdb/db5...
+ find /opt/app/oracle/oradata/acdb/db5 -name archive_logs.*.bz2 -type f -mtime +7 -exec /bin/rm -f {} ;
find: cannot get 'pwd'


I am at a loss, I have it working properly on another machine... (same script)
john korterman
Honored Contributor

Re: error: find: cannot get 'pwd'

Hi,
try finishing your find command with space backslash semicolon, e.g.:
{} \;
instead of the qouted semicolon.

regards,
John K.
it would be nice if you always got a second chance
Elmar P. Kolkman
Honored Contributor

Re: error: find: cannot get 'pwd'

What you can do is do a '-print' or '-exec echo rm -f {} \;' to see how far the find comes.

The message you get is something that happens when you try to find your path in a directory that is not readable/executable by the user. You say you are root, so in normal cases that's not the case (root bypasses normal security) UNLESS... there is a NFS mounted directory in the path (or perhaps the complete tree). '-xdev' might solve the problem in the first case, otherwise run the script on the NFS server instead of the NFS client.
Every problem has at least one solution. Only some solutions are harder to find.
Dietmar Konermann
Honored Contributor
Solution

Re: error: find: cannot get 'pwd'

The find(1) command issues that messaage if this call fails:

home_fd = open(".", O_RDONLY)

So the effective user calling find(1) cannot open the current working directory for reading.

From root's crontab you call:

su acadmin -c ...

The script is called as user 'acadmin' with root's HOME directory as working directory. Assuming that no cd(1) is done inside your script, are you sure that 'acadmin' has read permission to this directoty?

Check this:
# su acadmin -c 'ls ~root'


Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Ratzie
Super Advisor

Re: error: find: cannot get 'pwd'

In order to correct the problem I cd to the variable first, then did a find.

I think you are right, it may be a permissions problem, the script works perfectly on another machine.

Thanks for all the help.