views:

81

answers:

5

I need to set up a cron job that runs an executable compiled using gcc once every hour.

I logged in as root and typed crontab -e

Then I entered the following and saved the file.

0 * * * *  /path_to_executable

However, the cron job does not work.

I see that when I type /...path_to_executable I get a segmentation fault. I can only execute the executable from the folder it is located in. Is there a way I can solve this problem?

A: 

use

path_to_exe >> log_file

to see the output of your command also errors can be redirected with

path_to_exe &> log_file

also you can use

crontab -l

to check that your edits are saved

jartieda
crontab -l shows the cron job when I login as root.I tried the log_file but it is empty.
Anonymous
+2  A: 
0 * * * * cd folder_containing_exe && ./exe_name

should work unless there is something else that needs to be setup for the program to run.

joast
use , otherwise interessting stuff may happen (especially when used with rm)
Tass
joast
Thanks. This works.
Anonymous
A: 

Since I could not run the c executable that way, I wrote a simple shell script that does the following

cd /..path_to_shell_script ./c_executable_name

In the cron jobs list, I call the shell script.

Anonymous
+1  A: 

Did you mean the executable fails to run , if invoked from any other directory? This is rather a bug on the executable. One potential reason could be the executable requires some shared libraires from the installed folder. You may check environment variable (LD_LIBRARY_PATH)

Jayan
+1  A: 

The right way to solve this is to find out why you're getting the segmentation fault, and fix that.

David Thornley