0

I have a script in my server that displays its performance to the user in a text file. When the same script is executed in parallel by multiple users the information in the text file gets mixed up. I append many details of the server in the text file which takes roughly less than a minute to come up with the output. If i do file locking will it hit the performance or is there any way i need to look upon.

Please help me on how to proceed .

Thanks Balakrishnan

  • is using a database not an option? – Uku Loskit Sep 01 '13 at 12:24
  • It takes a minute to get the data, but how long does it take to write it to the file? Get the data, then lock the file, then output the data, then unlock the file. – William Pursell Sep 01 '13 at 13:29
  • @Willam , I can't use lock flock or lock file concept here as file may be execute by multiple users , it is an menu driven shell scipt to fetch the system details , performance details and many other details of remote machine through the same script . – Balakrishnan Sep 03 '13 at 18:19

2 Answers2

0

You could make use of a message queueing system:

POSIX message queues: http://www.linuxhowtos.org/manpages/7/mq_overview.htm

Beanstalkd: http://kr.github.io/beanstalkd/

POSIX Message Queue for Ruby: http://rubygems.org/gems/posix_mq

Perl: http://search.cpan.org/~iljatabac/POSIX-RT-MQ-0.03/MQ.pm

Python IPC: http://semanchuk.com/philip/posix_ipc/

Other threads:

Are message queues obsolete in linux?

https://unix.stackexchange.com/questions/70837/linux-command-to-check-posix-message-queue

https://stackoverflow.com/questions/40296/what-is-the-best-free-tool-for-managing-msmq-queues-and-messages

The idea is to create a server process that would receive messages and store on a buffer. It would only print a line on the logfile everytime a message from a process already has a complete line.

Community
  • 1
  • 1
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • Thank you for the reply However i am not having root credenital of my server so i could not able to mount the mqueue file system .Do we have any other way through shell script to allow the multiple users to append the output to a single file other than locking concept .Below is my piece of code – echo "IP Address :" $(ssh root@acb.server.com 'hostname -i' ) >> /tmp/server.txt echo "Operating System:"$(ssh root@acb.server.com 'uname -sr') >> /tmp/server.txt Where i am fetching the details from the remote machine and appending output to a single text file . – Balakrishnan Sep 03 '13 at 18:50
  • @balakrishnanse Can you not consider file databases with concurrency features instead? http://www.sqlite.org/lockingv3.html – konsolebox Sep 03 '13 at 19:27
  • If not a problem can you please explain me through examples ? – Balakrishnan Sep 04 '13 at 07:19
-1

FLoM http://sourceforge.net/projects/flom/ can manage the lock you need: it's easy to use, it's fast, the same resource can be locked/unlocked by different users and it implements a rich lock model.

This example use case could give you some ideas about the tool: http://sourceforge.net/p/flom/wiki/Use%20Case%206/

Cheers

Ch.F.

tiian
  • 29
  • 2