LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-18-2009, 10:17 AM   #1
ruisselet
LQ Newbie
 
Registered: Nov 2009
Distribution: Debian, Ubuntu
Posts: 2

Rep: Reputation: 1
Question Prevent editing/truncating file but not deletion (unlink)


I would like to make sure a file's content (the inode content) cannot be modified in any way, but still allow deleting (unlinking) the file (rationale below). That is, I could like to do something to file dest so that 'cp source dest' fails, even as root, but 'cp --remove-destination source dest' succeeds. The only thing I could find is to use chattr +i on the file. However, that also prevents unlinking. Is there a better solution?

The reason for this is that the file is a jar, used by a running java virtual machine. I want to update the code with a new version (with the same file name), but keep the previous instance of the JVM running for some time until it finishes its job. That will work if I first unlink the jar, but not if I use plain cp, which will by default truncate and overwrite the file's content, creating havoc and crashes in the running JVM. Since that is running a server used in production by hundreds of people simultaneously, I would like to make sure this never happens because I did a plain cp by mistake.

Thanks for any help and information.
 
Old 11-18-2009, 10:40 AM   #2
er1ch
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 1
Quote:
Originally Posted by ruisselet View Post
I would like to make sure a file's content (the inode content) cannot be modified in any way, but still allow deleting (unlinking) the file (rationale below). That is, I could like to do something to file dest so that 'cp source dest' fails, even as root, but 'cp --remove-destination source dest' succeeds. The only thing I could find is to use chattr +i on the file. However, that also prevents unlinking. Is there a better solution?
To be honest, this problem surpasses my capacities.

In such cases I write a small script, or better a shell function, e.g.

function Jar_Remove {

DEST=my_destination
SOUR=my_source

chattr -i $DEST

echo "Chattr -i $DEST..."

cp --remove-destination $SOUR $DEST

echo "Remove $DEST and copying $SOUR to $DEST..."

chattr +i $DEST

echo "chattr restored."

}

export -f Jar_Remove

This function with the export in a file sourced by .bashrc. It is perhaps not elegant, but your destination is safe, and only the call of Jar_Remove by root does the right thing. If you want to use it as a user, use "sudo".

HTH er1ch
 
  


Reply

Tags
chattr, cp


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
BASH: Truncating file names with special character tboss888 Programming 2 12-18-2008 07:28 PM
Prevent folder deletion, centos 5 danedmo Linux - Newbie 2 10-01-2008 10:40 PM
Truncating a file in linux bobbera Linux - Software 2 09-09-2008 07:51 AM
Mail File Sizes and Truncating Them mcupples Linux - Server 6 04-03-2007 08:59 AM
File Deletion mhkhalqani Linux - General 1 10-12-2005 03:08 AM


All times are GMT -5. The time now is 08:14 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration