inotify is a linux kernel feature, introduced recently, mainly to support desktop search produtcs like beagle.
This provides a mechanism for notificating processes of file system events. As I haven't seen many examples of how to use it, I'm writing this post to show you how you can use it in makefiles.
First of all, I use the inotifytools, downloadable http://inotify-tools.sourceforge.net/, and available for many distributions. Using these tools, I write makefiles that automatically trigger the compilation as soon as some file changed.
So, if I have a target in my makefile like:
output: file1 file2
gcc -o output file1 file2
I'll then write a line with something like:
cdeps = file1 file2
that is, a variable containing all files that my target depends on, again.
And then, some other line:
inotifywait:
while( true ); do inotifywait -e MOVE_SELF -e modify $(cdeps); make output; done
So, with these simple modifications, when you call:
make inotifywait
The command will wait for an event, when it reaches the command inotifywait. If you make some modification to some of your files, inotifywait will exit and then you'll have your event triggered, and in this case the event is make output.
This is the whole trick, quite useful when you're used to edit a file, change to a shell, compile, check the output and so on...
Wednesday, August 22, 2007
Wednesday, August 8, 2007
Monitoring your hosts with monit
I am writing this post mainly to publish a very small perl script I wrote to check the health of some server I own.
The script is very simple but useful, it generates output suitable for monit. There are many articles and reviews about this software, so I'm not writing anything else about it here, except that I like it very much because it is exactly the thing you need when you manage many servers.
Run the script by writing on the command line all hosts you want to check, either their names or IP addresses. It will generate a monit.d folder, containing a file for each host. These files contains all the information needed to check that their ssh port is accessible. Copy these file in /etc/monit.d, remember to add
include /etc/monit.d/*
to your /etc/monitrc file, and then start (or restart) monit itself.
If you give a look at the script, there's a line commented in it to enable also ICMP echo checks, in case you need it.
The script can be downloaded here.
The script is very simple but useful, it generates output suitable for monit. There are many articles and reviews about this software, so I'm not writing anything else about it here, except that I like it very much because it is exactly the thing you need when you manage many servers.
Run the script by writing on the command line all hosts you want to check, either their names or IP addresses. It will generate a monit.d folder, containing a file for each host. These files contains all the information needed to check that their ssh port is accessible. Copy these file in /etc/monit.d, remember to add
include /etc/monit.d/*
to your /etc/monitrc file, and then start (or restart) monit itself.
If you give a look at the script, there's a line commented in it to enable also ICMP echo checks, in case you need it.
The script can be downloaded here.
Thursday, August 2, 2007
Using Makefiles with OPNET
With this second post on OPNET I want to share a small script that I wrote to generate Makefiles to compile OPNET simulations.
The script is named makefile_gen.pl, it simply scans your op_models directory and outputs (on standard output) lines suitable to be put in a makefile.
So, if you want to generate a makefile for an optimized simulation, simply type:
$> cd
$> perl makefile_gen.pl 1 > opt_makefile
then, you can:
$> make -f opt_makefile dep
to generate dependencies, and
$> make -f opt_makefile
to compile all files. After this, the simulation will be linked only when you start it, either from modeler or from the command line. But with this small script, you have the advantage of compiling all the files that need be recompiled, and no more. And also, if you have more than one core/cpu, you can use "make -j 2" for instance, to enable parallel compilation.
You can download the script from here.
It has been tested using Linux, but should work on other platforms with some minor modification.
The script is named makefile_gen.pl, it simply scans your op_models directory and outputs (on standard output) lines suitable to be put in a makefile.
So, if you want to generate a makefile for an optimized simulation, simply type:
$> cd
$> perl makefile_gen.pl 1 > opt_makefile
then, you can:
$> make -f opt_makefile dep
to generate dependencies, and
$> make -f opt_makefile
to compile all files. After this, the simulation will be linked only when you start it, either from modeler or from the command line. But with this small script, you have the advantage of compiling all the files that need be recompiled, and no more. And also, if you have more than one core/cpu, you can use "make -j 2" for instance, to enable parallel compilation.
You can download the script from here.
It has been tested using Linux, but should work on other platforms with some minor modification.
Subscribe to:
Comments (Atom)