2

I had a simple Qt program, when running, it shows a simple window with a countdown timer. If you might be interested in the code, please see here.

I had crontab line

* * * * * /home/my-user-name/Documents/bin/program

When executing the comment /home/my-user-name/Documents/bin/program, the program runs correctly. But it's not invoked by the cron. I have multiple cron jobs, all run smoothly except this one.

My question is:

Do you have any idea what might cause this? Qt problem? PATH problem?

I have searched around for cron, and tried almost all the tips.

1 Answers1

3

The problem is that cron runs in a text environment. There are a few different approaches for that, depending on what your machine is running.

set a display variable:

* * * * * DISPLAY=:0.0 /home/my-user-name/Documents/bin/program

set up a password-less ssh key-pair and do

 * * * * * /usr/bin/ssh -y user@localhost /home/my-user-name/Documents/bin/program
tink
  • 6,765
  • You saved my day! Thanks. BTW, Any document for this? – gongzhitaao Sep 08 '14 at 20:50
  • 1
    You're welcome. I can't think of any document that states this explicitly. It's more of a matter of knowing how Unix/Linux works, and realising that crond runs before X. So, even if a cron job gets run as a user, it won't inherit the knowledge of the users X-Session (or environment variables that are set after you log in). – tink Sep 08 '14 at 20:59
  • 1
    @gongzhitaao When you run a program in UNIX world, you can before running initialize a env variabel such as : root@debian:/opt /ldoce5# myvar=googooli ./ldoce5-bin & Each program when that run, has a directory with its PID in /proc/, in my example: /proc/21959/ and each process has a file named environ, i use cat environ , i saw the following result: myvar=googooliXDG_VTNR=7ORBIT_SOCKETDIR=/tmp/orbit-mohsenXDG_SESSION_ID=10SSH_AGENT_PID=6196TERMINATOR_UUID (yes a set of variable and you can see myvar) – PersianGulf Sep 08 '14 at 21:00