Using smartmontools – smartd and conky (with cron) to monitor HDD health

conky is one hack of a great monitoring tools, but it misses the use of S.M.A.R.T. technology (as far as I know) to monitor hard-disk health, specifically use of smartmontools.

I present here quite dirty, but simple and easily extensible, way to include information from smartctl in conky output.

Continue reading

Makefile Generator, version 2

genmake, the Not so Simple Makefile Generator Bash Script, is now hosted on Google Code (for older version, check this post).

The version 2 now supports:

  • executables, static libraries, and dynamic link libraries, based on the output file name format,
  • automatic increment of build number on each build (the header file including the version and build number is automatically generated; requires Awk),
  • several build targets – debug, debug profile, release, release profile,
  • easily specifying additional flags passed to compiler,
  • passing list of link libraries used for build,
  • selectively excluding files from build, and more…

Happy coding! 🙂

Increase build number in C/C++ header (using Awk)

This trick works with most IDE’s that use pre-build step, but easiest I guess is to use it in a Makefile. Feel free to modify the “script” in any way it suites your purposes.

Suppose you have a build number defined as #define BuildNum 1 in BuildNum.h header.

All you have to do is add the following command in your make all section in Makefile ahead of other dependencies (it’s one line, broken here for visibility):

awk '$2 !~ /BuildNum/ {print} $2 ~ /BuildNum/ {print "#define BuildNum "$3+1}'\
    BuildNum.h > BuildNum.h~; mv BuildNum.h~ BuildNum.h

Yes, it’s a clumsy solution, but it does the work just fine… 😀 Sure, you can catch the lines in array, and afterwards print them one by one back to file, etc. … but it’s just not at all pretty bash script (enhancements and suggestions welcome!).

Notice that the command is pretty much dependent on the format of the line the BuildNum is defined on, and that “BuildNum” should not appear anywhere else as a second word on the line!

Practical Introduction to BASH

BASH, aka Bourne Again SHell, is probably the most wide-spread shell for *nix like systems (no discussions about this, please; if you prefer some other, just enjoy, I’m not making anyone use bash).

There are many intros out there, but most of them are more about syntax etc., with just a little practical use.
I wrote quite a few bash scripts, but it’s not my primary “language” of choice; so I often need a fast reminder, rather than textbook. That’s why I compiled this simple “list” or “intro” to use as a reference. Maybe someone else will find this useful also.

Continue reading

HowTo: Virtual Serial Ports on Linux using socat, and more

socat (SOcket CAT) – multipurpose relay – is a command line based utility that establishes two bidirectional byte streams and transfers data between them.
socat is #4 on the Top 100 Network Security Tools list, available in most distro repositories (on Debian/Ubuntu sudo apt-get install socat does the trick), really light on resources, and very efficient.
Sounds simple, does wonders!

Sidenote: socat is actually #71 on the mentioned list, but since socat is a much enhanced version of netcat, which is #4, it seems to me logical to count socat as #4 also.

One of the wonders you can do is creating pairs of “virtual” ports/interfaces/sockets etc., even hybrid pairs like port-socket, etc., where one (or both) ends of the pair can also be real objects. See socat man page for more details.

Continue reading