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 Answer 1

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
3
  • You saved my day! Thanks. BTW, Any document for this? Commented Sep 8, 2014 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). Commented Sep 8, 2014 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) Commented Sep 8, 2014 at 21:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.