Wednesday, August 24, 2011

devil is in the details.. #!/bin/bash

What's wrong with this:
su user -c "bash -xe" << 'EOF'
   my script
Sometimes writing constructs you have not used million times can cost precious time, in case you are *not* absolutely sure about all implications.

There is really nothing wrong with the above code if "my script" is very short and you understand deeply what it does. But if not, you may end up with your script terminating in the middle and ext code being 0 which is something I didn't expect from a script run with `-xe` options.

In my case I had a long script that just ended in the middle on an apache-ant invocation and script result was successful in our CI system. The problem is actually that apache-ant for some reason sucked everything on its stdin which in this case happened to be the rest of my script. Bash it seems, does not read the whole input so commands and programs called from within the script can eat parts of your script.

I've no idea why the particular apache-ant build never asks questions and completes happily with < /dev/null and still it eats the stdin. Maybe that's why it took me so much time to see the cause. I hope this is the reason it took me so much time to see the cause!

Conclusion is: use what you're absolutely confident in, alternatively plan some time in ahead for debugging:
cat > << 'EOF'
   my script
su user -- -xe
P.S. "bash -c"  is also solid for one liners

Monday, July 11, 2011

XXKB to the rescue

 I had problems with xfce keyboard layout switcher often dieing on suspend. Updating to newer and more stable version is cumbersome. So I did a quick search and found xxkb. It's very nice because I can have a language indicator on the window titlebar instead of filling the limited space in tray.

The only problem I had was that an indicator showed up in my tray. Fortunately xxkb is customizable so here's my config:
  • disable mainwindow (tray or a window indicator)
  • ignoring the tray/panel which is actually a window on it's own.
  • fixing indicator position
  • setting flag to be correct for my xkb configuration (yes, you need to configure xkb by other means, xkb only control its state)

One can use the xlsclients program to list all windows currently connected to the X11 server. I used it to find out the window name of the XFCE panel.

UPDATE: actually there is a better way, hold Ctrl, Shift or both and middle click the xxkb button you want to remove, that will update .xxkbrc automatically but will wipe all comments in the file. Unfortunately some windows don't have a name or class so still are a problem.

Below is my ~/.xxkbrc :
XXkb.mainwindow.enable: no
! XXkb.mainwindow.type:tray
! XXkb.button.enable: no
XXkb.app_list.wm_name.ignore: xfce4-panel
XXkb.button.geometry: 15x15-100+3
XXkb.button.image.2: bg15.xpm

Update: To ignore desktop use:
Xkb.app_list.wm_class_class.ignore: Xfdesktop