Cron jobs not working as expected

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have setup 3 crontab jobs to execute my simple ruby scripts periodically every minute, 5 minutes and hour. They execute, however they do not do anything. I have only one user on the machine (root) and I have setup the crontab by executing the command crontab -e. crontab -l lists my current crontab jobs:



5 * * * * ruby /root/www/server-monitoring/current/tasks/cpu_check.rb
0 * * * * ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb
1 * * * * ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb


I can see that they execute but not in the right intervals and also they do not do anything whereas if I execute those ruby files manually they work perfectly fine. I can confirm that the ruby programs work fine 100%, they pass tests, etc. Here are the crontab logs:



Dec 6 15:45:01 monitoring-jedrzej CRON[28281]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 15:55:01 monitoring-jedrzej CRON[28478]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:00:01 monitoring-jedrzej CRON[28584]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb)
Dec 6 16:01:01 monitoring-jedrzej CRON[28614]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28702]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/cpu_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28703]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:15:01 monitoring-jedrzej CRON[29214]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)


What am I missing here?







share|improve this question






















  • Full path to ruby maybe? Like /usr/bin/ruby?
    – JdeHaan
    Dec 6 '17 at 17:19















up vote
1
down vote

favorite












I have setup 3 crontab jobs to execute my simple ruby scripts periodically every minute, 5 minutes and hour. They execute, however they do not do anything. I have only one user on the machine (root) and I have setup the crontab by executing the command crontab -e. crontab -l lists my current crontab jobs:



5 * * * * ruby /root/www/server-monitoring/current/tasks/cpu_check.rb
0 * * * * ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb
1 * * * * ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb


I can see that they execute but not in the right intervals and also they do not do anything whereas if I execute those ruby files manually they work perfectly fine. I can confirm that the ruby programs work fine 100%, they pass tests, etc. Here are the crontab logs:



Dec 6 15:45:01 monitoring-jedrzej CRON[28281]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 15:55:01 monitoring-jedrzej CRON[28478]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:00:01 monitoring-jedrzej CRON[28584]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb)
Dec 6 16:01:01 monitoring-jedrzej CRON[28614]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28702]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/cpu_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28703]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:15:01 monitoring-jedrzej CRON[29214]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)


What am I missing here?







share|improve this question






















  • Full path to ruby maybe? Like /usr/bin/ruby?
    – JdeHaan
    Dec 6 '17 at 17:19













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have setup 3 crontab jobs to execute my simple ruby scripts periodically every minute, 5 minutes and hour. They execute, however they do not do anything. I have only one user on the machine (root) and I have setup the crontab by executing the command crontab -e. crontab -l lists my current crontab jobs:



5 * * * * ruby /root/www/server-monitoring/current/tasks/cpu_check.rb
0 * * * * ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb
1 * * * * ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb


I can see that they execute but not in the right intervals and also they do not do anything whereas if I execute those ruby files manually they work perfectly fine. I can confirm that the ruby programs work fine 100%, they pass tests, etc. Here are the crontab logs:



Dec 6 15:45:01 monitoring-jedrzej CRON[28281]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 15:55:01 monitoring-jedrzej CRON[28478]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:00:01 monitoring-jedrzej CRON[28584]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb)
Dec 6 16:01:01 monitoring-jedrzej CRON[28614]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28702]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/cpu_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28703]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:15:01 monitoring-jedrzej CRON[29214]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)


What am I missing here?







share|improve this question














I have setup 3 crontab jobs to execute my simple ruby scripts periodically every minute, 5 minutes and hour. They execute, however they do not do anything. I have only one user on the machine (root) and I have setup the crontab by executing the command crontab -e. crontab -l lists my current crontab jobs:



5 * * * * ruby /root/www/server-monitoring/current/tasks/cpu_check.rb
0 * * * * ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb
1 * * * * ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb


I can see that they execute but not in the right intervals and also they do not do anything whereas if I execute those ruby files manually they work perfectly fine. I can confirm that the ruby programs work fine 100%, they pass tests, etc. Here are the crontab logs:



Dec 6 15:45:01 monitoring-jedrzej CRON[28281]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 15:55:01 monitoring-jedrzej CRON[28478]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:00:01 monitoring-jedrzej CRON[28584]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_disk_space.rb)
Dec 6 16:01:01 monitoring-jedrzej CRON[28614]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/free_ram_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28702]: (root) CMD (ruby /root/www/server-monitoring/current/tasks/cpu_check.rb)
Dec 6 16:05:01 monitoring-jedrzej CRON[28703]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 6 16:15:01 monitoring-jedrzej CRON[29214]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)


What am I missing here?









share|improve this question













share|improve this question




share|improve this question








edited Dec 6 '17 at 17:37









Patrick Mevzek

2,0381721




2,0381721










asked Dec 6 '17 at 16:59









jedi

1186




1186











  • Full path to ruby maybe? Like /usr/bin/ruby?
    – JdeHaan
    Dec 6 '17 at 17:19

















  • Full path to ruby maybe? Like /usr/bin/ruby?
    – JdeHaan
    Dec 6 '17 at 17:19
















Full path to ruby maybe? Like /usr/bin/ruby?
– JdeHaan
Dec 6 '17 at 17:19





Full path to ruby maybe? Like /usr/bin/ruby?
– JdeHaan
Dec 6 '17 at 17:19











2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










You have not set these jobs to run every minute, every 5 minutes, and every hour. All three are set to run once per hour, at :01 past the hour, :05 past the hour, and :00 past the hour. Instead you might try something like



* * * * * echo 'run every minute'
*/5 * * * * echo 'run every 5 minutes'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * echo 'alternate every-five-minute'
0 * * * * echo 'run every hour on the hour'





share|improve this answer




















  • Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
    – jedi
    Dec 6 '17 at 17:42










  • I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
    – jedi
    Dec 6 '17 at 17:45

















up vote
2
down vote













Generally, you'll find that this is an environment issue. Running a script from cron does NOT execute the /etc/profile script. You can source /etc/profile at the start of the script, or set just those variables that you'll need for your script (PATH is one that comes quickly to mind).



I'd suggest creating a small script that runs the env command and pipe that to a file so that you can see exactly what your environment is when running something from cron. Should help you find what is not set that needs to be.






share|improve this answer






















  • Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
    – jedi
    Dec 6 '17 at 17:26






  • 2




    I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
    – James C. Woodburn
    Dec 6 '17 at 17:36











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409257%2fcron-jobs-not-working-as-expected%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










You have not set these jobs to run every minute, every 5 minutes, and every hour. All three are set to run once per hour, at :01 past the hour, :05 past the hour, and :00 past the hour. Instead you might try something like



* * * * * echo 'run every minute'
*/5 * * * * echo 'run every 5 minutes'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * echo 'alternate every-five-minute'
0 * * * * echo 'run every hour on the hour'





share|improve this answer




















  • Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
    – jedi
    Dec 6 '17 at 17:42










  • I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
    – jedi
    Dec 6 '17 at 17:45














up vote
1
down vote



accepted










You have not set these jobs to run every minute, every 5 minutes, and every hour. All three are set to run once per hour, at :01 past the hour, :05 past the hour, and :00 past the hour. Instead you might try something like



* * * * * echo 'run every minute'
*/5 * * * * echo 'run every 5 minutes'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * echo 'alternate every-five-minute'
0 * * * * echo 'run every hour on the hour'





share|improve this answer




















  • Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
    – jedi
    Dec 6 '17 at 17:42










  • I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
    – jedi
    Dec 6 '17 at 17:45












up vote
1
down vote



accepted







up vote
1
down vote



accepted






You have not set these jobs to run every minute, every 5 minutes, and every hour. All three are set to run once per hour, at :01 past the hour, :05 past the hour, and :00 past the hour. Instead you might try something like



* * * * * echo 'run every minute'
*/5 * * * * echo 'run every 5 minutes'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * echo 'alternate every-five-minute'
0 * * * * echo 'run every hour on the hour'





share|improve this answer












You have not set these jobs to run every minute, every 5 minutes, and every hour. All three are set to run once per hour, at :01 past the hour, :05 past the hour, and :00 past the hour. Instead you might try something like



* * * * * echo 'run every minute'
*/5 * * * * echo 'run every 5 minutes'
0,5,10,15,20,25,30,35,40,45,50,55 * * * * echo 'alternate every-five-minute'
0 * * * * echo 'run every hour on the hour'






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 6 '17 at 17:36









user4556274

4,97811123




4,97811123











  • Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
    – jedi
    Dec 6 '17 at 17:42










  • I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
    – jedi
    Dec 6 '17 at 17:45
















  • Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
    – jedi
    Dec 6 '17 at 17:42










  • I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
    – jedi
    Dec 6 '17 at 17:45















Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
– jedi
Dec 6 '17 at 17:42




Oh stupid me...I totally missed this. Thank yo uso much! You've made my day!
– jedi
Dec 6 '17 at 17:42












I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
– jedi
Dec 6 '17 at 17:45




I have accidently found a note on RVM site that 'For every installed ruby and created gemset RVM creates wrappers for basic command line tools like gem, rake, ruby' and I should actually do this: /usr/local/rvm/wrappers/ruby-2.3.0/ruby /path/to/script.rb and it worked!
– jedi
Dec 6 '17 at 17:45












up vote
2
down vote













Generally, you'll find that this is an environment issue. Running a script from cron does NOT execute the /etc/profile script. You can source /etc/profile at the start of the script, or set just those variables that you'll need for your script (PATH is one that comes quickly to mind).



I'd suggest creating a small script that runs the env command and pipe that to a file so that you can see exactly what your environment is when running something from cron. Should help you find what is not set that needs to be.






share|improve this answer






















  • Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
    – jedi
    Dec 6 '17 at 17:26






  • 2




    I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
    – James C. Woodburn
    Dec 6 '17 at 17:36















up vote
2
down vote













Generally, you'll find that this is an environment issue. Running a script from cron does NOT execute the /etc/profile script. You can source /etc/profile at the start of the script, or set just those variables that you'll need for your script (PATH is one that comes quickly to mind).



I'd suggest creating a small script that runs the env command and pipe that to a file so that you can see exactly what your environment is when running something from cron. Should help you find what is not set that needs to be.






share|improve this answer






















  • Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
    – jedi
    Dec 6 '17 at 17:26






  • 2




    I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
    – James C. Woodburn
    Dec 6 '17 at 17:36













up vote
2
down vote










up vote
2
down vote









Generally, you'll find that this is an environment issue. Running a script from cron does NOT execute the /etc/profile script. You can source /etc/profile at the start of the script, or set just those variables that you'll need for your script (PATH is one that comes quickly to mind).



I'd suggest creating a small script that runs the env command and pipe that to a file so that you can see exactly what your environment is when running something from cron. Should help you find what is not set that needs to be.






share|improve this answer














Generally, you'll find that this is an environment issue. Running a script from cron does NOT execute the /etc/profile script. You can source /etc/profile at the start of the script, or set just those variables that you'll need for your script (PATH is one that comes quickly to mind).



I'd suggest creating a small script that runs the env command and pipe that to a file so that you can see exactly what your environment is when running something from cron. Should help you find what is not set that needs to be.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 6 '17 at 17:37









Patrick Mevzek

2,0381721




2,0381721










answered Dec 6 '17 at 17:21









James C. Woodburn

213




213











  • Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
    – jedi
    Dec 6 '17 at 17:26






  • 2




    I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
    – James C. Woodburn
    Dec 6 '17 at 17:36

















  • Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
    – jedi
    Dec 6 '17 at 17:26






  • 2




    I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
    – James C. Woodburn
    Dec 6 '17 at 17:36
















Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
– jedi
Dec 6 '17 at 17:26




Thank you. I also noticed that they do not run at the right intervals. The first job should run every 5 mintues, the second job every hour and the last one every mintue, however, as you can see in the logs, they do not execute in the right interval. Any ideas?
– jedi
Dec 6 '17 at 17:26




2




2




I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
– James C. Woodburn
Dec 6 '17 at 17:36





I hadn't looked at that. The minute in crontab is what minute of the hour to execute that script, not how many minutes apart. You should be able to add a comma separated list of minutes (00,05,10,15, ...) to get it to do what you want, but that gets tedious. Looking into it a little, I see that you should be able to do */5 for every five minutes, */2 for every two minutes, and */1 for every minute.
– James C. Woodburn
Dec 6 '17 at 17:36


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409257%2fcron-jobs-not-working-as-expected%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?