Having a bit of trouble trying to sort this one out so any advice is appreciated.
I have several scripts running in cron monitoring different events on different servers. These scripts log information events and critical events to a central log file.
I wanted to add an event number to every logged event in the file so I have a file with a number in it to start - say 000000
Then in every script I have the following when I log any event:
curevent=`tail -1 /logs/eventnums | cut -f1 -d" "`
eventnum=$(($curevent + 1))
echo "$eventnum event info" >>/logs/central_events.log
echo $eventnum > /logs/eventnums
/logs/eventnums is where I keep the latest event number and its updated by the cron scripts everytime they take a number...
Problem is that some of the scripts have to run at the same time in cron and so eventually they take the same eventnum each and update the eventnums file at the same time so I end up with events with the same number which is no good..
Use a lock file. Like this:
Before we do anything, we can check for existence of the lock file and loop while it exists. Then when we get the all clear, we touch a lock file and then get to work. Once the job is done, we remove the lock file and let other cron jobs get on with it.
Yes - I did think of using a lock mechanism.. but had not tried it as some of these scripts work at the same second and I wondered whether it would work it both scripts see no lock - both touch a lock file and then continue to use the event number...
Use a lock file. Like this:
Before we do anything, we can check for existence of the lock file and loop while it exists. Then when we get the all clear, we touch a lock file and then get to work. Once the job is done, we remove the lock file and let other cron jobs get on with it.
--This is not tested--
torch,
if we are using a separate lock file to maintain integrity there is always a problem that it could be corrupted or accidentally deleted during processing.
here is a very similiary approach to yours, to make use of the existing file and work around with the permission bits
what types of methods and algorithms are used to track random number generators? I'm working on computer security, and I want to know all the different ways to track random number generators so I know what to counter (8 Replies)
Is there a way to track down what process is sending to a certain port? I have some thing pounding the network with requests to a multicast IP that doesn't exist. I have shut down all comms related processes and yet it is still there. Need a way to track the port or IP back to the process. Thanks... (3 Replies)
Hi,
OS: Solaris9, SPARC
Is there any way I can track the commands run by users from the shell prompt?
Example:
Somebody is deleting files from the system. Who it is is a mystery. That person obviously does not use bash prompt so there is no history. Is there anyway I can find out who... (5 Replies)