Jump to content

Crontab not working D:

JessicaH
Go to solution Solved by cynexit,
2 minutes ago, JessicaH said:

My top gotcha: If you forget to add a newline at the end of the crontab file. In other words, the crontab file should end with an empty line.

I AM 50% SURE THIS IS THE PROBLEM

 

Good catch, I'll try to explain my stuff none the less, maybe it'll help you in the future. :)

 

You know what the stars do, just to make sure we're on the same page here: the stars specify the interval which in your case is every minute.

 

Now, since a .sh file is just a file containing shell commands you need an actual shell to execute the file. It's the same as for .py files where you need the python interpreter. Most of the time the system knows how to execute a .sh file (by passing it to sh (the standard shell), bash or zsh), but under certain circumstances it will not know how to run the file since it's not a native ELF binary. In this case you just point to the binary (the shell in our case) and give it the file path to execute.

 

So what I did was instead of calling the .sh file directly I called the shell with /usr/bin/sh and supplied the sh script as first parameter to make sure the correct shell is spawned and the script is actually executed.

 

For the redirect stuff I'll just redirect you to this very good answer: http://unix.stackexchange.com/questions/163352/what-does-dev-null-21-mean-in-this-article-of-crontab-basics

*/1 * * * * /home/jessh/directory1/directory2/cron.sh >/dev/null 2>&1

When i try to do this, it wont execute...

 

What am I doing wrong?

OS: Ubuntu Server 16.04

Here is the error log...

Sep 15 09:25:01 jessh CRON[24333]: (jessie) CMD (/home/jessie/testing/testing/cron.sh >/dev/null 2>&1)
Sep 15 09:26:01 jessh CRON[24678]: (jessie) CMD (cd /home/jessie/testing/testing/ cron.sh >/dev/null 2>&1)
Sep 15 09:27:01 jessh CRON[24782]: (jessie) CMD (cd /home/jessie/testing/testing/ sh cron.sh >/dev/null 2>&1)
Sep 15 09:28:01 jessh CRON[24865]: (jessie) CMD (cd /home/jessie/testing/testing/ sh cron.sh >/dev/null 2>&1)

I tried two different methods...

None of which worked

For line 1:

*/1 * * * * cd /home/jessie/testing/testing/ cron.sh >/dev/null 2>&1 >/dev/null 2

Line 2 is the same, just with the different command at the end

cd /home/jessie/testing/testing/ sh cron.sh >/dev/null 2>&1

Help :( 

I installed postfix too, it didn't change anything

 

cron.sh is just a command that creates a file named file.txt

Link to comment
Share on other sites

Link to post
Share on other sites

Try:

*/1 * * * * /usr/bin/sh /home/jessh/directory1/directory2/cron.sh > /dev/null 2>&1

If this does not work out, remove the redirect and check the output.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, cynexit said:

Try:


*/1 * * * * /usr/bin/sh /home/jessh/directory1/directory2/cron.sh > /dev/null 2>&1

If this does not work out, remove the redirect and check the output.

explain to me what each command does

*/1 * * * * /usr/bin/sh /home/jessh/directory1/directory2/cron.sh > /dev/null 2>&1

i know what the stars do

you specified a directory of some sort... what is /usr/bin/sh ? is it where my sh file is located?

and i know that /home/jessh/directory1/directory2/cron.sh is executing the .sh file, correct?

It would be very kind if you could explain it to me.

Thank you.

btw, i followed this wiki, and env showed the path varaible as something else.

http://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work

i think i have to set the path variable at the top of the script

 

how exactly would i do that in my case?

Link to comment
Share on other sites

Link to post
Share on other sites

oh shit

My top gotcha: If you forget to add a newline at the end of the crontab file. In other words, the crontab file should end with an empty line.

I AM 50% SURE THIS IS THE PROBLEM

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, JessicaH said:

My top gotcha: If you forget to add a newline at the end of the crontab file. In other words, the crontab file should end with an empty line.

I AM 50% SURE THIS IS THE PROBLEM

 

Good catch, I'll try to explain my stuff none the less, maybe it'll help you in the future. :)

 

You know what the stars do, just to make sure we're on the same page here: the stars specify the interval which in your case is every minute.

 

Now, since a .sh file is just a file containing shell commands you need an actual shell to execute the file. It's the same as for .py files where you need the python interpreter. Most of the time the system knows how to execute a .sh file (by passing it to sh (the standard shell), bash or zsh), but under certain circumstances it will not know how to run the file since it's not a native ELF binary. In this case you just point to the binary (the shell in our case) and give it the file path to execute.

 

So what I did was instead of calling the .sh file directly I called the shell with /usr/bin/sh and supplied the sh script as first parameter to make sure the correct shell is spawned and the script is actually executed.

 

For the redirect stuff I'll just redirect you to this very good answer: http://unix.stackexchange.com/questions/163352/what-does-dev-null-21-mean-in-this-article-of-crontab-basics

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, cynexit said:

 

Good catch, I'll try to explain my stuff none the less, maybe it'll help you in the future. :)

 

You know what the stars do, just to make sure we're on the same page here: the stars specify the interval which in your case is every minute.

 

Now, since a .sh file is just a file containing shell commands you need an actual shell to execute the file. It's the same as for .py files where you need the python interpreter. Most of the time the system knows how to execute a .sh file (by passing it to sh (the standard shell), bash or zsh), but under certain circumstances it will not know how to run the file since it's not a native ELF binary. In this case you just point to the binary (the shell in our case) and give it the file path to execute.

 

So what I did was instead of calling the .sh file directly I called the shell with /usr/bin/sh and supplied the sh script as first parameter to make sure the correct shell is spawned and the script is actually executed.

 

For the redirect stuff I'll just redirect you to this very good answer: http://unix.stackexchange.com/questions/163352/what-does-dev-null-21-mean-in-this-article-of-crontab-basics

Wow! thank you so much! This was very informative!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×