2

Let's say I have a small "Hello World" Java program compiled in my home directory. I can run it with java helloWorld from my home directory and it executes without any problem.

Now I need to schedule to execute this program let's say after 10mins from now. So, I am executing following commands on console:

at now+10min
warning: commands will be executed using /bin/sh
at> java helloWorld
Press CTRL+D to finish

So it is scheduled properly as I can see it with at -l command. But at this time nothing happens.

Why? What is wrong with it? Because, if instead of scheduling the execution my own program I schedule executing of gedit command it opens it at a specified time. But with my own program it doesn't perform anything. How can I change the situation?

Bruno Pereira
  • 73,643
Bakhtiyor
  • 12,254

2 Answers2

2

What does helloworld do? If it is text application, you would not see the output (unless you setup to receive the cron reports to your local e-mail). If it is a GUI application, it will not work because cron cannot start GUI applications.

Therefore, try with a Java application that creates a file on your system (for example, in /tmp) and observe whether it happens.

In addition, use the MAILTO option in crontab so that you are sure that cron runs properly. The notification e-mails include the output of the program (for example, the message Hello world!) and any errors in running the commands.

user4124
  • 8,911
  • It is a simple test application which shows Hello World message. – Bakhtiyor Jan 29 '11 at 14:34
  • I have checked out writing to the file from my application in order to see whether it has been executed or not. So, yes, it has been executed. But as you said it doesn't show print messages. – Bakhtiyor Jan 29 '11 at 15:03
  • When you enable the MAILTO option in crontab, you are able to see the output of the command you added. Therefore, from this e-mail you can see the output of the program you put. – user4124 Jan 29 '11 at 15:23
  • @user4124: Cron can start any GUI. Just add DISPLAY=:0.0 to the crontab –  Sep 03 '13 at 14:00
0

Try giving the full path of the file, eg:

java /home/ward/prog/helloWorld