Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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.
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?
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
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.
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".
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.
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.
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?
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.
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.
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).
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.