Wednesday 29 August 2012

Observing tips #2 — Keeping an observing log

In the old days, we all used to keep observing logs. It would have the date and time of all the things that we did, what we were looking at and any notes that we thought were important along the way. It was in a log book; yes, a physical book and the notes would all be hand-written.

Things have moved on, of course, and these days the telescope control, the data acquisition and the data processing are all done on computers. While some of us still keep log books, it is all too easy to forget to write down a command or two... usually the critical one that you need to remember later (because it had lots of arguments!).

As most of our systems use Linux (or some other UNIX-like environment), there is the "history" command, which can be used to see all the commands that have been put into the system. This is very useful. For example:

   % history
    1  ls
    2  ls - ltr
    3  cat obs_notes.txt
    4  history

But by default it does not include the time when the command was issued. However, there is a way around this. In bash (a common shell used on many Linux systems), the history command will check for the history format shell variable. So, you can set this before running your history command (in fact, it might be useful to put it in your startup script, such as .bashrc).

   % export HISTTIMEFORMAT="%Y%m%d-%H%M%S %% "

Then, when you run your history command, you get this:

   % history
    1014  20120827-114212 % swlevel 3
    1015  20120827-114218 % rspctl --regstat
    1016  20120827-114347 % 5
    1017  20120827-114410 % rspctl --rcu
    1018  20120827-114422 % cd

I prefer to use the compact format "YYYYMMDD-HHMMSS", because that way you can sort on this field. While this may seem superfluous for a simple example like this, what may happen is that there are commands coming in for all sorts of different terminals. So, what you can then do is to save them all, and then sort by time.

For example, in the first terminal:

   term1% history >> obs_notes.txt

And then, in the second terminal:

   term2% history >> obs_notes.txt
   term2% sort -k 2 obs_notes.txt

The sort command will then put them all into order for you. Note that you need to use ">>", not ">" in order to append to the obs_notes.txt file. Otherwise you simply overwrite the previous version.

Of course, you can play around with awk and grep and sed to get other fancy formatting, but you get the idea.

Hope it helps!

No comments:

Post a Comment

Note: only a member of this blog may post a comment.