Thursday, 12 February 2009

autohibernate, zenity and cron

I have been trying to make a script that should put my laptop into hibernate, run automatically from cron, so it forces me to get to sleep.

I had managed to make it work from a console (tty1), but it seemed as if it refused to work from cron.

During the tests my local mailbox was getting the output of the command, and I stood and watched at this error message for more than an hour trying to figure out what was wrong. I couldn't understand what was wrong:

This option is not available. Please see --help for all possible usages.

This was from zenity and I was starting to suspect that it was failing to expad properly the text variable since it worked with a fixed text.

This was failing:

(...) | /usr/bin/zenity --progress --auto-close --text "'$NOTIFICATION$XMSG'"

And this was working:

(...) | /usr/bin/zenity --progress --auto-close --text "OH!MY!GOD!"

I couldn't figure it out. Until I tried this:

(...) | /usr/bin/zenity --progress --auto-close --text "OH!MY!GOD!îîăăîăî"

And it failed.

God damn! Setting LANG in the script fixed the issue right away!

So, if you ever want zenity to show up from cron dont forget to:
  • set DISPLAY
  • set LANG
zenity is a pice of shit when it doesn't work. It could have printed the "option which wasn't available".