Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crontab - simple echo not running

I've got such situation: I want to schedule a job with crontab on a linux server. I'm not super-user, so I'm editing (with crontab -l, editor vim) only my crontab file. For testing, I put there:

* * * * * echo asdf 

And the job is not running. Is the restart of the server needed? Or maybe some administrator move?

like image 799
zlenyk Avatar asked Mar 04 '15 13:03

zlenyk


People also ask

Why does my cron job not run?

You might discover that your job works when run via the command line, but won't run via cron. This may be due to the location you're executing from or the PATH you're using. The use of relative paths is a common cause of cron issues. In cron, the PATH is set by default to /bin:/usr/bin .

How do you check the cron job is running or not?

To check to see if the cron daemon is running, search the running processes with the ps command. The cron daemon's command will show up in the output as crond. The entry in this output for grep crond can be ignored but the other entry for crond can be seen running as root. This shows that the cron daemon is running.

How do I run a cron job every 5 seconds?

Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.


1 Answers

May be it is, cron jobs will run in their own shell. So you can't expect to see asdf on your console.

What you should try is

* * * * * echo asdf > somefile_in_your_home_directory_with_complete_path.log 

Next check the file by doing a tail:

tail -f somefile_in_your_home_directory_with_complete_path.log 

And if it's not, check if the cron daemon itself is running or is down:

# pgrep crond 

OR

# service crond status 
like image 179
Kedar Parikh Avatar answered Oct 01 '22 14:10

Kedar Parikh