How to configure cron job to run executable every hour?

I need to configure a cron job that runs an executable compiled using gcc once an 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 error. I can execute the executable file only from the folder in which it is located. Is there any way to solve this problem?

+74
c gcc linux cron crontab
Aug 13 '10 at 6:02
source share
7 answers
 0 * * * * cd folder_containing_exe && ./exe_name 

should work if you don't need anything else to run the program.

+125
Aug 13 '10 at 16:31
source share

The correct way to solve this is to find out why you are getting a segmentation error and fix it.

+4
Aug 20 '10 at 19:52
source share

If you use Ubuntu, you can put the shell script in one of the following folders: /etc/cron.daily , /etc/cron.hourly , /etc/cron.monthly or /etc/cron.weekly .

Check out this post for more details: https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job

+3
Feb 24 '17 at 19:33
source share

Since I was unable to run the C executable , I wrote a simple shell script that executes the following

 cd /..path_to_shell_script ./c_executable_name 

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

+1
Aug 13 '10 at 16:31
source share

Did you mean that the executable does not start if it is called from any other directory? It is rather an error in the executable file. One potential reason may be that the executable requires some common libraires from the installed folder. You can check the environment variable LD_LIBRARY_PATH

+1
Aug 13 '10 at 16:51
source share

You can also use @hourly instant 0 * * * *

+1
Dec 27 '16 at 9:39
source share

use

 path_to_exe >> log_file 

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

 path_to_exe &> log_file 

also you can use

crontab -l

to check that your changes are saved

-one
Aug 13 '10 at 6:07
source share