Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the Geany IDE for programming, and it does not reliably reload my previously open files, for example after a power outage. I found that Geany has a command line feature which returns a list of all open files in the editor, so I hoped that I could quickly write a cron command that would automatically save that list every hour or so.

I currently have this line in my crontab:

0 * * * * ~/bin/save_geany_files

and the script contains just one line:

geany --list-documents > ~/geany_files.txt

This does not work. I noticed that Geany's --list-documents feature must be called by the same user (I think), so I tried adding "su - [myusername]" to the script, but apparently su cannot be used from within a cron job? So, I am at a loss for how to automate this. I am open to any other solutions to my problem, although Geany options/plugins seem to be unreliable (which is why I tried this in the first place)

share|improve this question
Have you made ~/bin/save_geany_files executable? It should work without the su (cron jobs are run by the user whose crontab it is) as long as the "script" (not really a script) is executable. – terdon Apr 29 '13 at 19:07
Commands in your crontab (i.e. added via crontab without a -u argument) run under your account by default. Unless you're running geany as a user other than yourself, which seems mildly unlikely, the problem has to be somewhere else, e.g., with @terdon's suggestion that maybe the shell script isn't executable. – Aaron Miller Apr 29 '13 at 19:08
And, as a more general solution, you might consider using a more reliable editor; I've found Emacs (which has long-standing and well-tested session save and restore facilities) quite suitable. (I know -- "Emacs? Augh!" -- but don't believe the hype! Emacs is extremely intuitive, once you've spent several years learning how it works. :) – Aaron Miller Apr 29 '13 at 19:15
@terdon: Yes, the file is executable. I thought cron jobs were run as the owner, but I put in a debugging line, echo "user: $USER", and in the output it shows just user: , so I'm confused. I'm not running Geany as a different user. – monguin Apr 29 '13 at 22:33
I'm not opposed to learning emacs, but that's something I'd do on my own time, so it will have to wait for a while. – monguin Apr 29 '13 at 22:34

By running the crontab like this:

0 * * * * ~/bin/save_geany_files 2> /tmp/geanyerror.log

I found this error message in /tmp/geanyerror.log:

Geany: cannot open display

I solved this by adding the following line to .bashrc:

xhost local:arune > /dev/null

(where arune is my username) and changing my crontab to

0 * * * * export DISPLAY=:0.0 && ~/bin/save_geany_files 2> /tmp/geanyerror.log

My own save_geany_files-script looks like this:

cp /home/arune/geany/savenew.txt /home/arune/geany/saveold.txt
/usr/bin/geany --list-documents > /home/arune/geany/savenew.txt

to store a "backup" for one hour extra.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .