Cron jobs not working as expected
Clash 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?
debian cron
add a comment |Â
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?
debian cron
Full path to ruby maybe? Like /usr/bin/ruby?
â JdeHaan
Dec 6 '17 at 17:19
add a comment |Â
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?
debian cron
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?
debian cron
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
add a comment |Â
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
add a comment |Â
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'
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
add a comment |Â
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.
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
add a comment |Â
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'
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
add a comment |Â
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'
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
add a comment |Â
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'
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'
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
add a comment |Â
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Full path to ruby maybe? Like /usr/bin/ruby?
â JdeHaan
Dec 6 '17 at 17:19