The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Prevent users logging in as root Sepia SUN Solaris 3 06-05-2008 10:45 AM
Multiple Sessions with FTAM gauravgoel UNIX for Advanced & Expert Users 0 03-14-2008 01:37 AM
Users Are Getting Kicked out of 2Hr Sessions Sarccastik Dude AIX 2 07-23-2007 07:07 PM
Prevent file from being mailed multiple times from a job Sree_2503 Shell Programming and Scripting 2 11-14-2006 09:47 AM
How to prevent root users from editing files (logs) vehchi UNIX for Dummies Questions & Answers 4 12-06-2005 03:29 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-30-2006
Registered User
 

Join Date: Nov 2005
Location: Canada
Posts: 30
Locking a file when using VI to prevent multiple-edit sessions by diff users

At the office, we often have to edit one file with VI. We are 4-6 workers doing it and sometimes can be done at the same time.

We have found a problem and want to prevent it with a file lock. Is it possible and how ?

problem :

Worker-a starts edit VI session on File-A at 1PM
Worker-b starts edit VI session on File-A at 1:05PM

worker-a changes 100 lines and exit/saves at 2:00PM
worker-b changes 1 line and exit/saves at 2:15PM

as result, changes done by worker-a are lost
we even had cases where losts of lines being edited were lost.

if we could lock the file upon editing it with VI, it woud prevent others from editing it and would have to wait for whomever is in to finish before being able to edit it.
Reply With Quote
Forum Sponsor
  #2  
Old 10-31-2006
andryk's Avatar
Registered User
 

Join Date: Sep 2003
Posts: 448
not really a convenient solution ...

I would do that the hard way ... recompile from the source
Get the source, modify so to open in read-only mode (and warn user) if the lock file is present!
Not really what you're looking for i guess (though the modification should be straight)
Reply With Quote
  #3  
Old 10-31-2006
Registered User
 

Join Date: Sep 2006
Posts: 208
instant messaging, send a message to all other users that you are hacking around in the file so the others know to hold off until you are done.
i cannot think of an easy way with file locking to prevent your problem.
we have several dev boxes that we modify or reboot at random and we use instant messaging to broadcast a message that we are doing some changes, seems to work for us.
Reply With Quote
  #4  
Old 11-10-2006
Registered User
 

Join Date: Nov 2005
Location: Canada
Posts: 30
locking via shell script ?

Isn't there a unix (AIX) command that can lock or unlock a file ?

That way we could simply execute a small script that would do :

if file not locked
lock file
vi file
unlock file
else
echo "file being edited"
Reply With Quote
  #5  
Old 11-10-2006
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,477
A revision management system such as CVS and Subversion will eliminate all of your worries in the long run.

Do not let everybody modify the production version. Have every staff checkout a local copy, which everyone modifies on their own, commit to CVS, and at last only update the production version by the administrator after the current version has been considered okay.

Best of all, such systems can help you keep the revision history of every file managed, so you literally never lose anything!
Reply With Quote
  #6  
Old 11-14-2006
Registered User
 

Join Date: Jul 2006
Posts: 16
Maybe you can either:
1.
ask the user to do a ps -ef before editing the file
cerntst1:/# ps -ef | grep test
root 478570 611346 0 15:29:18 pts/2 0:00 vi test.txt <-----
root 647012 51760 0 15:29:39 pts/3 0:00 grep test

or
2.
create a program to detect the vi process and if vi test.txt is showing up in the process, exit.
Reply With Quote
  #7  
Old 11-14-2006
Registered User
 

Join Date: Oct 2002
Posts: 676
Like cbkihong said, revision control is the way to go. You could even use a built-in system like rcs.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0