LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-01-2011, 07:09 PM   #1
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Rep: Reputation: Disabled
cron job not working?


I have a cron job to run every 15 minutes. The cron job is running per /var/log/cron. It lists the job every 15 minutes.

Jun 1 23:30:01 Nginx crond[17361]: (app_user) CMD (/bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production '\''Cron.reminderPostoffice'\''')
Jun 1 23:45:01 Nginx crond[17570]: (app_user) CMD (/bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production '\''Cron.reminderPostoffice'\''')

I do not see any errors. I also looked in /var/log/messages for any errors and it does not list any. I added a line to the script that is running to send an email to me to see if it is running or not. When I run the script from the command line, the script runs without error and I get an email. I have searched and can not find what it going on. Is there some where else errors might be? Could there be a permission issue? The cron job is not being added by the root user.
 
Old 06-01-2011, 08:35 PM   #2
LMW
Member
 
Registered: Oct 2010
Location: Russia / USA
Distribution: Arch Linux
Posts: 36

Rep: Reputation: 2
Quote:
Originally Posted by tekram View Post
I have a cron job to run every 15 minutes. The cron job is running per /var/log/cron. It lists the job every 15 minutes.

Jun 1 23:30:01 Nginx crond[17361]: (app_user) CMD (/bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production '\''Cron.reminderPostoffice'\''')
Jun 1 23:45:01 Nginx crond[17570]: (app_user) CMD (/bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production '\''Cron.reminderPostoffice'\''')

I do not see any errors. I also looked in /var/log/messages for any errors and it does not list any. I added a line to the script that is running to send an email to me to see if it is running or not. When I run the script from the command line, the script runs without error and I get an email. I have searched and can not find what it going on. Is there some where else errors might be? Could there be a permission issue? The cron job is not being added by the root user.
So, what's your question? This script is not performing what you want him to or what? Did you check execute permissions on it? What does "ls -la" show?
 
Old 06-01-2011, 08:50 PM   #3
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Yes, the cron job is not producing the result it is suppose to. I put a testing line in there to send an email to me showing me that the script was executed.

How do I check execution permissions?

Thanks!
 
Old 06-01-2011, 08:56 PM   #4
LMW
Member
 
Registered: Oct 2010
Location: Russia / USA
Distribution: Arch Linux
Posts: 36

Rep: Reputation: 2
Quote:
Originally Posted by tekram View Post
Yes, the cron job is not producing the result it is suppose to. I put a testing line in there to send an email to me showing me that the script was executed.

How do I check execution permissions?

Thanks!
First, please see what does "ls -la /path/to/script" show. Can you execute it from command line? Does it produce what you expect?
 
Old 06-02-2011, 10:23 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by tekram View Post
Yes, the cron job is not producing the result it is suppose to. I put a testing line in there to send an email to me showing me that the script was executed.
That's a sophisticated test that could fail for several reasons; a more dependable test (assuming your script is a shell script) would be echo "Hello" > /tmp/some_unique_name_like_this
 
Old 06-02-2011, 03:05 PM   #6
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
The script I am trying to run is not a shell script but a ruby script.

Permission on the fil are as follows:
-rw-rw-r-- 1 app_user app_user 2175 Jun 1 21:35 rails_apps/xxx/releases/20110531232110/app/models/cron.rb

So, the user does not have execution permissions but is it needed? When I run the script with the ruby interpreter from the command line, it executes fine without errors with the expected output.

As a test, I added the echo command above to also run every 15 min

0,15,30,45 * * * * echo "Hello" > /tmp/crontest

It does run and does create that file. For some strange reason, it (the fact that this line was executed) does not show up in logs under /var/log/cron.

Thanks.
 
Old 06-02-2011, 10:18 PM   #7
LMW
Member
 
Registered: Oct 2010
Location: Russia / USA
Distribution: Arch Linux
Posts: 36

Rep: Reputation: 2
Quote:
Originally Posted by tekram View Post
The script I am trying to run is not a shell script but a ruby script.

Permission on the fil are as follows:
-rw-rw-r-- 1 app_user app_user 2175 Jun 1 21:35 rails_apps/xxx/releases/20110531232110/app/models/cron.rb

So, the user does not have execution permissions but is it needed? When I run the script with the ruby interpreter from the command line, it executes fine without errors with the expected output.

As a test, I added the echo command above to also run every 15 min

0,15,30,45 * * * * echo "Hello" > /tmp/crontest

It does run and does create that file. For some strange reason, it (the fact that this line was executed) does not show up in logs under /var/log/cron.

Thanks.
Well, you can add execution permission by typing "chmod +x /path/to/your/script".

Best regards,
Konstantin
 
Old 06-03-2011, 12:06 AM   #8
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Will try that.

So, as a learning point. When there is a script that needs to be executed but not a shell script do the permission need to be changed to execute? If so, how come the file can be executed from the command line otherwise. That is I can execute the script by calling the ruby interpreter with the file.

Thanks!
 
Old 06-03-2011, 06:20 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The script needs execute permission if it is to be run directly but not if it is to be run by some other program as you are doing with script/rails.

Are you running it exactly the same way at the command line, that is with
Code:
cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production 'Cron.reminderPostoffice'
Can you post the crontab line? Which cron system are you running? Is it Dillon's or Vixie? The crond or cron man page may show.
 
Old 06-03-2011, 10:35 AM   #10
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
NB: As an interactive user you will have a different environment (like $PATH/$LD_LIBRARY_PATH) set than when the same is run from a cron job. Inside the crontab you can therefore define these environment variables.
 
Old 06-05-2011, 01:10 PM   #11
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Here is the exact cron line:

0,15,30,45 * * * * /bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production '\''Cron.reminderPostoffice'\'''

I am running Vixie.

In terms of the path question, should I not get an error if the path is not set correctly? Is there a way to check the path variables for the user that runs the crontab? Is it root?
 
Old 06-05-2011, 01:26 PM   #12
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by tekram View Post
Here is the exact cron line:

0,15,30,45 * * * * /bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && script/rails runner -e production '\''Cron.reminderPostoffice'\'''

I am running Vixie.

In terms of the path question, should I not get an error if the path is not set correctly? Is there a way to check the path variables for the user that runs the crontab? Is it root?
When you installed it under a user account with crontab -e it is run under this user account. For the ones defiend in /etc/crontab and alike you would have an additional column therein specifying the user.

You could setup a cron entry just echoing the $PATH and other environment variables.
 
Old 06-06-2011, 10:38 PM   #13
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Well, it rutne out that if I added the command ruby before the second command in the cron line. it seemed to work.


0,15,30,45 * * * * /bin/bash -l -c 'cd /home/app_user/rails_apps/xxx/releases/20110531232110 && ruby script/rails runner -e production '\''Cron.reminderPostoffice'\'''

I also outputed the $PATH and it was different. however, i did nto need to change to get the cron job to work. i will look more into it tomorrow but i am wondering if perhaps there is another ruby interpretter located in the default path locations?

being still new to linux, why does it work when adding the "ruby" command and not without it? also, how come i could not find the error logged telling my why the cron job failed? i looked in the typical places and found no log of it.
 
Old 06-07-2011, 12:51 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
What is the first line of /home/app_user/rails_apps/xxx/releases/20110531232110/script/rails?

It could be a shebang line, for example #! /usr/bin/ruby

You can find the ruby executables in the directories listed in $PATH by which ruby or type ruby (which also checks for shell aliases, functions etc. so is more thorough).

Which typical places did you look? Could be /var/log/cron (may be distro-specific) or mail sent to the user that cron ran the command for (try running mail or mailx at the command prompt as that user or peeking in /var/spool/mail to see which users have mail).
 
Old 06-09-2011, 06:48 PM   #15
tekram
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
The first line was a shebang. Thanks for educating me on that. The path was wrong for my production server ruby interpreter which is why it was not working. That was really helpful.

I looked in /var/log/cron and /var/log/messages. I am not using a local mail server to send that email out. I am using Gmail through an SMTP connection. Are there any other places I should look?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Job in /etc/cron.d not working BrianK Linux - General 6 11-03-2011 09:03 AM
[SOLVED] Cron job not working 2handband Slackware 7 11-14-2010 09:29 AM
cron job not working bittus Linux - Software 7 04-27-2009 07:39 PM
Cron Job Not Working... ALInux Linux - Software 2 07-24-2007 04:15 AM
Cron job not quite working... simba_cubs Linux - General 10 11-08-2006 06:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration