How to set up a cron job to run an executable every hour?

后端 未结 7 2354
迷失自我
迷失自我 2020-11-30 21:59

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

相关标签:
7条回答
  • 2020-11-30 22:35

    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

    0 讨论(0)
  • 2020-11-30 22:36

    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.

    0 讨论(0)
  • 2020-11-30 22:37
    0 * * * * cd folder_containing_exe && ./exe_name
    

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

    0 讨论(0)
  • 2020-11-30 22:42

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

    0 讨论(0)
  • 2020-11-30 22:48

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

    0 讨论(0)
  • 2020-11-30 22:50

    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 if your edits were saved.

    0 讨论(0)
提交回复
热议问题