how do i lock a ksh shell script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ndedhia1
    New Member
    • Jan 2009
    • 112

    how do i lock a ksh shell script

    Hi,
    I have a ksh shell script that accesses databases to drop and create tables and the script also creates text files.
    This shell script is accessed thru a java application that i would like to turn multi-user, but the only way that i can do that is if I can figure out a way to lock the shell script so that only 1 user can access it at a time.
    If 2 or more users access it, then bad things happen when 2 users and trying to drop and create the same database at the same time, or trying to create the same text file at the same time.

    I would also like for the user to wait till the shell script is unlocked, instead of just passing over it or ending the application.

    please help!!

    thanks!!
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    I'm not sure how deep into the working of Linux you want to get, but you could just create a hidden file that is something like a system command (I think - a call that lets you run command-line commands inside a program) like 'touch .programname.lo ck', and have your script check to see if it exists or not before executing (and when it's done, remove the file through 'rm .programname.lo ck'. I know this functionality exists in Linux, however I don't know the calls to set it up through Java, but I'm sure a Google search would be able to help with that.

    On the wait - how do you want your program to behave? Do you want it to keep trying (keep looking for the lock file) every 5/10/20 seconds? Or do you want to inform the user, and suggest they run the program again later?

    I'd recommend coming up with the specific functionality you want - that will make it easier to code.

    Comment

    Working...