want file to regenerate after deletion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting want file to regenerate after deletion
# 1  
Old 09-17-2009
want file to regenerate after deletion

I looked into the sticky bit, but I think, if possible, that I would prefer to have the file recreate itself after deletion. The file is several directories deep, and from time to time the top level directory will be trashed. I need the file to recreate after this. Is it possible to perhaps create a symlink that, if the file is deleted, the source file will recreate it?

---------- Post updated at 03:33 PM ---------- Previous update was at 02:56 PM ----------

Any ideas are welcome!
# 2  
Old 09-17-2009
Do you want the file contents re-created or just a the file? If just the file, have a script that checks to see if the target file exists and if not, touch $file. If you want the contents as well, have a similar script that checks for existence and if it isn't there, copy a new one in place. From what you say you'll probably have to create the directory structure as well. Have a look at mkdir -p for that.
# 3  
Old 09-17-2009
peterro, Thanks for answering.. I was wondering if there was something simpler.. Like a way to actually have a symlink that, if the target file was deleted, that the source file would recreate it.
# 4  
Old 09-17-2009
Can you give more details? What is trashing your directory structure? Is this just a blank file, or a log file that you will be writing to when needed? I don't understand why you'd want to keep recreating a dir structure and a file. Without knowing more I'd tend to agree with peterro's comments.
# 5  
Old 09-17-2009
There's no fundamental-to-the-system way to make a file that ressurects itself. If you want to leave a file alone, the natural thing to do is to stop trashing it! Smilie And change file and directory permissions to prevent people from trashing it in the first place. I'm reminded of a story:
Quote:
From: tzs@stein.u.washington.edu (Tim Smith)
Organization: University of Washington, Seattle

I was working on a line printer spooler, which lived in /etc. I wanted to remove it, and so issued the command "rm /etc/lpspl." There was only one problem. Out of habit, I typed "passwd" after "/etc/" and removed the password file. Oops.

I called up the person who handled backups, and he restored the password file.

A couple of days later, I did it again! This time, after he restored it, he made a link, /etc/safe_from_tim.

About a week later, I overwrote /etc/passwd, rather than removing it.

After he restored it again, he installed a daemon that kept a copy of /etc/passwd, on another file system, and automatically restored it if it appeared to have been damaged.

Fortunately, I finished my work on /etc/lpspl around this time, so we didn't have to see if I could find a way to wipe out a couple of filesystems...
# 6  
Old 09-17-2009
try using hard links.

ie:
Code:
ln /myfs/protected/directory/master.file /myfs/dir/that/might/be/trashed/your.copy.file

if your.copy.file gets removed, you can just create another link. keep master.file in a safe place and you will always have at least one file there. the files must exist on the same file system though. the file will only be unlinked if all references are removed.
# 7  
Old 09-18-2009
I am using a link. This file is a userChrome.css file within a user's firefox profile that is configured to disable/remove the network settings button so that users arent changing their proxy settings. The problem is sometimes the users' firefox profile gets corrupted and we trash it. When firefox starts up after that, it creates a new profile, minus the userChrome.css file which is custom. I was hoping I could use a linked userchrome file in their profile, and if it was deleted, to have it somehow regenerate from the destination linked file. basically a link that when broken, fixes itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File content deletion

Hi Everyone, There are certain files under a folder 'ABC' and the entries for these files are there in another file(fname) under a different folder 'XYZ'. I want to compare the folder contents(ABC) with the file(fname) contents and delete the mismatching / non-existing ones from the file,... (4 Replies)
Discussion started by: swasid
4 Replies

2. UNIX for Dummies Questions & Answers

How Do I Regenerate the Shadow file

I guess the earlier problem I had with changing user passwords and creating new users is related to the shadow file. Anytime I change something to /etc/passwd or shadow I get locked out. HOW DO I REGENERATE THIS FILE. (1 Reply)
Discussion started by: Waitstejo
1 Replies

3. Shell Programming and Scripting

Deletion of lines in a text file

Hi Everyone, Please help me with this. I have gone through many posts here but couldn't find what I wanted. I have a file with 79000+ lines and I want to delete lines in a pattern. I want to delete every 141st line in the file, starting from line 2000 till 50000. Please help guys. ... (8 Replies)
Discussion started by: max29583
8 Replies

4. Programming

How to watch for file creation/deletion?

How do I write a C program that will watch a directory for file creation/deletion? Maybe it would receive a signal when someone creates a file? thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

5. Shell Programming and Scripting

Prompting for file deletion?

I got help in another forum but now I need further help so I figured I'd ask here. I had to write a script to delete certain filenames of certain size. I got this far.. find . -size 110c -name "*testing*" -print | xargs -n 1 rm -i It finds the correct files, but the prompts to delete are all... (2 Replies)
Discussion started by: NycUnxer
2 Replies

6. UNIX for Dummies Questions & Answers

file deletion problem

I am using unix via telnet ssh and i have a problem I was testing the server. I made a directory. Transfered a file from an ftp to it. Opened the file with the vi text editor --This where my problem came..... I tried deleting the file using rm somefile.htm when is typed ls i noticed that... (2 Replies)
Discussion started by: shdwsclan
2 Replies

7. UNIX for Dummies Questions & Answers

large file deletion

OS: Solaris 8 I deleted a large file (around 13 Gigs) from my system. But the output of df -k remains the same. The capacity % is constant. However one strange thing is happening- My available space is decreasing, my used space in increasing (The opposite should happen). This is happening... (2 Replies)
Discussion started by: run_time_error
2 Replies

8. UNIX for Dummies Questions & Answers

Deletion of File in Unix

Hi there guys. I'm quite new in using unix and just recently experienced missing file problem. Someone accidentally or likely intentionally deleted one specific folders that contains important file. Now my question is, can any other user aside from root can do such action? Please help. ... (2 Replies)
Discussion started by: rhomel101
2 Replies

9. Shell Programming and Scripting

File deletion when server restarts

Hi, In a shell script I am makin use of 3 files f1,f2 and f3.txt. When the Unix server is restarted I want to delete all these 3 files if they are existing. ( I suppose I will have to use this command rm /thefilepath/f* but dont know in which script to use.) Anyone knows what can be... (6 Replies)
Discussion started by: k_oops9
6 Replies
Login or Register to Ask a Question