Operating System - HP-UX
1821849 Members
3262 Online
109638 Solutions
New Discussion юеВ

Re: rm : permission denied ?

 
steven Burgess_2
Honored Contributor

rm : permission denied ?

Hi all

I've been asked to look at a script to see why a lock file every now and then can't be removed.

The line of code from the script is pretty straight forward. A user xxadmin creates the lock and then , when the ftp process is finished removes the file he created

############################################
# Remove pincab_transfer locking mechanism #
############################################
remove_pincab_lock()
{
if [ -f ${PINLOCK} ]; then
rm -f ${PINLOCK} >> ${ERM} 2>&1
res=$?
if [ ${res} -ne 0 ]; then
echo " Failed to remove lock file ${PINLOCK} " >> ${ERM}
app_mesg="Failed to remove lock file ${PINLOCK}"
app_alert
else
echo " Removed lock file ${PINLOCK}" >> ${ERM}
fi
fi
}

The problem isn't just on one server. The lock file is in /tmp

drwxrwxrwx 136 root sys 55296 Dec 19 22:10 /tmp

The permissions on the file are

-rw-rw-rw- 1 xxadmin support 0 Dec 19 22:14 /tmp/pincab_lock

The output from the log is

Starting pincab_transfer (PID=3518) at 13:22:04

Created lock file /tmp/pincab.lock
Config file has been read O.K.
PING connection to 164.39.253.60 is available at 13:22:04
Found 2 new file(s) for transmission
Found 0 file(s) for re-transmission
Attempting to send 2 file(s) in total
Problems moving data from /tmp to /tmp/incab_hold
rm: /tmp/pincab.lock not removed. Permission denied
Failed to remove lock file /tmp/pincab.lock

Any ideas ?

Thanks in advance for any input

Regards

Steve


take your time and think things through
12 REPLIES 12
Ken Hubnik_2
Honored Contributor

Re: rm : permission denied ?

Since you are using FTP maybe the file hasn't completed transferring therefor it cannot be removed. If you notice during the ftp there are no file permissions until the file is completely transferred. Just a thought
Pete Randall
Outstanding Contributor

Re: rm : permission denied ?

Hi Steven,

A couple thoughts:

1) Does the "Problems moving data from /tmp to /tmp/incab_hold" possibly enter into this, or do you see that at other times.

2) Can you insert a ll of the file in question into the script right after the creation and right before the move?

It's a strange one all right.

Pete

Pete
steven Burgess_2
Honored Contributor

Re: rm : permission denied ?

Hi

The file is created before the process then removed after checks have been made that the ftp is completed, therefore isn't actually part of the ftp

Thanks

Steve
take your time and think things through
John Poff
Honored Contributor

Re: rm : permission denied ?

Hi Steve,

Can you post the code where the lock file gets created?

JP
steven Burgess_2
Honored Contributor

Re: rm : permission denied ?

Hi Pete

Thats what I was looking at also. I fetched all the logs from all the servers from today but only found one instance of the failure, so couldn't see if there was a pattern. Something to think about though

I'll put an ll in the script also

Thanks

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: rm : permission denied ?

Here it is

check_pincab_running()
{
REMOVE_PINLOCK='N'

if [ -f /lock.pro ]; then
echo " Detected housekeeping is running" >> ${ERM}
exit_program
fi

if [ -f /lock.out ]; then
echo " Detected the machine is about to reboot" >> ${ERM}
exit_program
fi

if [ -f /lock.bkup ]; then
echo " Detected backup is running" >> ${ERM}
exit_program
fi

if [ -f ${PINLOCK} ]; then
echo " Detected ${PINLOCK} - assuming ${PROGRAM} already running" >> ${ER
M}
exit_program
else
(touch ${PINLOCK} 2>&1) > /dev/null
res=$?
if [ ${res} -ne 0 ]; then
echo " Failed to create pincab lock file - ${PINLOCK}" >> ${ERM}
exit_program
fi

echo " Created lock file ${PINLOCK}" >> ${ERM}
fi

The things is , it works 99% of the time , then every now and again fails

bizarre

Steve
take your time and think things through
Pete Randall
Outstanding Contributor

Re: rm : permission denied ?

Steve,

Admittedly, my scripting skills aren't the strongest but it looks good to me. I'm hoping the before and after "ll's" will give us a hint (though I think it's something a little more obtuse). You're right, it's bizarre.

Pete

Pete
Vincent Stedema
Esteemed Contributor

Re: rm : permission denied ?

Hmm,

You could perhaps add

fuser -u $PINLOCK

to your script to check if another process has locked the file.

Perhaps even

rm -f ${PINLOCK} >> ${ERM} 2>&1
while (( $? != 0 ))
do
echo "Can't remove file"
fuser -u $PINLOCK
sleep 10
rm -f ${PINLOCK} >> ${ERM} 2>&1
done

But this will hang the script until it's able to delete the file :-) Not sure if you would want to do that...

Regards,

Vincent
Sridhar Bhaskarla
Honored Contributor

Re: rm : permission denied ?

Hi Steve,

Just curious, keep the line

ll ${PINLOCK}

before rm -f statement in your script.

See what you would know everytime they complaied about it.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
steven Burgess_2
Honored Contributor

Re: rm : permission denied ?

Hi

This is what I have come up with to check

exit_program
else
(touch ${PINLOCK} 2>&1) > /dev/null
ll ${PINLOCK} >> ${ERM}

And

remove_pincab_lock()
{
if [ -f ${PINLOCK} ]; then
rm -f ${PINLOCK} >> ${ERM} 2>&1
res=$?
if [ ${res} -ne 0 ]; then
ll ${PINLOCK} >> ${ERM} 2>&1
sudo fuser -u ${PINLOCK} 2>&1| tr [")"] ["\n"] | grep \( |cut -d\( -f1 | t
r [":"] ["\n"] | egrep '[0-9][0-9][0-9]?' | tr ["o"] [" "] > /tmp/pinlock.pid
for i in $( do
dpd $i >> ${ERM} 2>&1
done
echo " Failed to remove lock file ${PINLOCK} " >> ${ERM}

The dpd is a small c prog to give full details of the pid and parents

I'll wait and see

Thanks

Steve


take your time and think things through
Carlos Fernandez Riera
Honored Contributor

Re: rm : permission denied ?

Few day ago i was amazed when as root i do a rm file and get permision denied.

The cuestion is the path i used was a symbolic link to a NFS mounted filesystem. I had to cd to original NFS mount point to remove the file.

HTH.
unsupported
Jean-Louis Phelix
Honored Contributor

Re: rm : permission denied ?

hi,

Perhaps your problem is related to /tmp mode. I've seen some system with S_ISVTX set on /tmp (ie drwxrwxrwt). In this case, anyone can create a file, but only the owner or root can delete it. From man 2 chmod :

If the mode bit S_ISVTX (sticky bit) is set on a directory, files inside the directory may be renamed or removed only by the owner of the file, the owner of the directory, or the superuser (even if the modes of the directory would otherwise allow such an operation).

Regards.
It works for me (┬й Bill McNAMARA ...)