1834178 Members
2438 Online
110064 Solutions
New Discussion

Appending file

 
Dayanand Naik
Frequent Advisor

Appending file

Hi,

Is there any way where any user can only append to a file without deleting it or modifying the contents of the file. Just pure adding.

for ex. the .sh_history file is own by the users itself. only the user can modify, add delete the contents other than root. The qts is is there any way where he user can just append to the file without deleting
the contents or modifying it.

Dayanand Naik
10 REPLIES 10
someone_4
Honored Contributor

Re: Appending file

What about script that appends a file to the file. For example have a regular file owned by the user. And then have a cron that goes and appends the data in the file to whatever file you want to append it to.
Prolly something like userfile.txt >> otherfile.txt. Im sure there will be more
solutions. And if my ideas is not too good .. Please tell me why !!

thanks

Richard =)
someone_4
Honored Contributor

Re: Appending file

opps
forgot that you have to cat the file to append it to the other file so it will look like this
if you have more then one file to append.
cat userfile >> mainfile
cat userfile2 >> mainfile

Richard
federico_3
Honored Contributor

Re: Appending file

If i have file1 and i want append to it file2 i can do:

cat file1 file2 > file3
mv file3 file1
or
cat file2 >> file1
Manju Kampli
Trusted Contributor

Re: Appending file

the answer is no .. when you give user a permission to write, he can delete the file as well
Never stop "LEARNING"
Klaus Crusius
Trusted Contributor

Re: Appending file


You could write a script (perferably a C-program), which appends to the given file. Assuming your target file is owned by user xxx who has write permission, but ther is no write permission for other users. Give the script owner xxx and chmod 4755 script, that will set the SETUID bit. (You need to be root or xxx to perform the chmod).
Every user with permission to execute this scrip will be able to append to you target file, but have no other permissions.
Klaus
There is a live before death!
James R. Ferguson
Acclaimed Contributor

Re: Appending file

Hi:

Yes, this can be done. Set the 'noclobber' option. You will be able to append but not to overwrite:

#!/usr/bin/sh
set -o noclobber
typeset F=/tmp/myfile
echo "...appending on...`date`" >> $F
echo "...appending on...`date`" >> $F
echo "...overwriting?...`date`" > $F
#.end.

...JRF...
Joseph C. Denman
Honored Contributor

Re: Appending file

Hi Day,

James is correct. The noclobber option would stop the file accidentally overwritten. However, if security is what your looking for, the noclobber will not do it.

example.

With noclobber on:
echo "test overwrite" > $F # will not overwrite file

However,
echo "test overwrite" >| $F #will overwrite file

If security is what you want, you will need to use the cron answer above.

hope this helps.

...jcd...
If I had only read the instructions first??
Deshpande Prashant
Honored Contributor

Re: Appending file

HI
If security is the issue, you can use third party security softwares to restrict access to files. I had used a software called SeOS from Platinum (2 years back) which can grant access to files as create/append/delete levels per users or group.

Thanks.
Prashant Deshpande.
Take it as it comes.
Jim Turner
HPE Pro

Re: Appending file

Deshpande,

Computer Associates bought Platinum and renamed SeOS to Etrust. It sucks rocks. We're talking great big boulders here. Of course, that's CA.

We have to run Etrust to meet audit requirements. Truthfully, though, I'd rather have my eyeballs eaten-out by rats rather than deal with SeOS any longer.

All the best,
Jim
Deshpande Prashant
Honored Contributor

Re: Appending file

Hi Jim
We at that time had only restricted its use for system files and did not go to its full implementation for its very own reasons, I only wanted to suggest to look at different security softwares to serve the purpose of file access restriction.

Prashant Deshpande.
Take it as it comes.