![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how can i replace "(", "\" "+" in a file | mail2sant | Shell Programming and Scripting | 3 | 04-22-2008 08:10 PM |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 12:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-19-2007 10:52 PM |
| "sed" to check file size & echo " " to destination file | jockey007 | Shell Programming and Scripting | 6 | 11-13-2007 06:00 PM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 01:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
"vi"-ing a constantly updated file
Hi,
A bit of a dumb question here. Sorry folks. Suppose I have this file which is being updated at irregular intervals (a few seconds, a few minutes, who knows) by a background process. I 'vi' this file with the intention of editing it, so it opens up a temp copy as the usual /tmp/720cwhatever Now suppose, whilst I have this file opened, its updated several times by the background process. I make my changes, save-quit. What happens to the updates that were made by the background process during the time I had the file opened? How do I mitigate this? (unfortunately, stopping the background process is not an option). The file is fairly big also (about 40Mb) so it takes vi a few seconds to load it up, save to it etc..... Unix is ksh. OS is SunOS. Hope you guys can help! - thanks in advance! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
The updates made by background process are not lost, the question is what happens when you are about to do "save & quit" - you will be prompted with message that the original file has changed : do you want to save anyway ?
The other thing is when someone else is trying to vi the same file opened by you - he will get a message : Quote:
|
|
#3
|
||||
|
||||
|
Percy, as sysgate noted, your solution will heavily depend on what exactly
you want to update in the file. Is it really necessary to "vi" the file? Could a shell be written to do the updates you want? |
|
#4
|
|||
|
|||
|
OK cheers guys!
A bit more info: What exactly I want to do is this: This is a big file, full of filenames and a hashcode for each filename. each line in the file is filename, date, hashcode filename, date, hashcode ... Anyway, so a file comes into a server, gets a hashcode which is then put into this big log file of mine, and then the file is processed. Should the file be sent in again to the server, its hashcode is checked and if it exists (ie, my process has dealt with it already) it deals with the file appropriately. I come unstuck when I need to reprocess the same file again - so I need to edit the large log file and remove the entry (the whole line - name,date,hashcode) so that I can feed it through again. Write a sh to deal with this? - not sure - its one of those where it happens often, but not often enough to justify a sh....but its something I guess I could look into. One other thing: Suppose two people sudos to a user (the same user) first, and then edits the file - you don't get the message about the file changing when you save/quit right? - at least that's what it appears to happen over here in bizarro world... |
|
#5
|
||||
|
||||
|
Percy,
Here is one possible solution: 1) Rename the "work_file" to a "tmp_file" and immediately create a new "work_file" so that new records can continue to be added to it. Code:
mv work_file tmp_file touch work_file 2.a) After you are finished with your changes on the "tmp_file", do not quit yet. 2.b) Go to the end of the "tmp_file" and in the command line type: Code:
:r work_file of "tmp_file". 2.c) Write and quit the "tmp_file". As you say the file is very large, if you try to save the work area as "work_file", it may take a long time and use a lot of memory and disk space. 3) Immediately rename "tmp_file" back to "work_file". Code:
mv tmp_file work_file |
|
#6
|
|||
|
|||
|
Thank you for this.
There is still the slight potential of missing additions to the logfile between steps 2c and 3 - and its mainly due to how fast I can type "mv file file2" - in a panic, I probably spend more time hitting the backspace than actually typing commands correctly. Its definitely a better catcher of entries than the solution I had in mind - so thanks very much! |
|
#7
|
||||
|
||||
|
I also want to point out that your question is not dumb at all, in my previous company we were 7 admins with root access + the process who was doing the updates of sensitive data files. There were moments that we had to edit the file manually, and, fortunately, we had the possibility to rewrite the deamon to accept responces that the files is inaccessible now, and batch the data for later insertion. That's why the question is not stupid, instead may turn into headache.
|
||||
| Google The UNIX and Linux Forums |