The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > 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 01:45 PM
Multiple Sessions with FTAM gauravgoel UNIX for Advanced & Expert Users 0 03-14-2008 04:37 AM
Users Are Getting Kicked out of 2Hr Sessions Sarccastik Dude AIX 2 07-23-2007 10:07 PM
Prevent file from being mailed multiple times from a job Sree_2503 Shell Programming and Scripting 2 11-14-2006 12:47 PM
How to prevent root users from editing files (logs) vehchi UNIX for Dummies Questions & Answers 4 12-06-2005 06:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2006
Browser_ice Browser_ice is offline
Registered User
  
 

Join Date: Nov 2005
Location: Canada
Posts: 110
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.
  #2 (permalink)  
Old 10-31-2006
andryk's Avatar
andryk andryk is offline Forum Advisor  
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)
  #3 (permalink)  
Old 10-31-2006
dukessd dukessd is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2006
Posts: 307
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.
  #4 (permalink)  
Old 11-10-2006
Browser_ice Browser_ice is offline
Registered User
  
 

Join Date: Nov 2005
Location: Canada
Posts: 110
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"
  #5 (permalink)  
Old 11-10-2006
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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!
  #6 (permalink)  
Old 11-14-2006
cchiang12 cchiang12 is offline
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.
  #7 (permalink)  
Old 11-14-2006
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
Like cbkihong said, revision control is the way to go. You could even use a built-in system like rcs.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0