I know this question has been asked many, many times and I've done a lot of research but still I'm not able to run this extremely simple cron:
$ crontab -l
* * * * * /bin/date
This should, ideally, print the date every minute.
There is no cron.allow or cron.deny file, and the cron daemon is working:
ps -e | grep cron
1119 ? 00:00:00 cron
17646 ? 00:00:00 cron
Any idea what might be wrong?
Cron processes run in a separate subprocess of their own, so the output of a cron job will not be visible to you in your shell.
Instead, you will have to capture the output of your cron commands and save them. So, set your cronjob like:
* * * * * /bin/date >> /home/user/date.log
And now, if you will tail this log file, you will start seeing the result.
Related
I have to write a cron job to execute a java class every after 8 hours. To test, I wrote a simple cron using :
crontab -e
*/1 * * * * echo $PATH
When I do, crontab -u <user> -l, it prints the entire cron file with above job listed. But I want to ascertain that my job is getting executed as intended. I don't see output of "echo $PATH" every minute. How can I see this output...?
I am trying to make a cron job for the first time but i have some problems making it work.
Here is what i have done so far:
Linux commands:
crontab -e
My cronjob looks like this:
1 * * * * wget -qO /dev/null http://mySite/myController/myView
Now when i look in:
/var/spool/cron/crontabs/
I get the following output:
marc root
if i open the file root
i see my cronjob (the one above)
However it doesnt seem like it is running.
is there a way i can check if its running or make sure that it is running?
By default cron jobs do have a log file. It should be in /var/log/syslog (depends on your system). Vouch for it and you're done. Else you can simply append the output to a log file manually by
1 * * * * wget http://mySite/myController/myView >> ~/my_log_file.txt
and see what's your output. Notice I've changed removed the quiet parameter from wget command so that there is some output.
I want to schedule a cron job in Linux by running a shell script.
The scenario is, I'm taking the time in HH:MM format in the shell script from the user and want to schedule a cron job from the shell script. I even want the cron job to be executed only once.
Thanks in advance...
For the crontab, you can do something like this:
cur=$(crontab -l)
new="$mm $hh * * * your_command"
echo "$cur$new" | crontab -
For one-shot, crontab is not the good candidate. Use at (note: your_command must be a file, e.g., a bash script)
at -f your_command $hh:$mm
At first, this is not exactly a programming question and more specific to Linux. I hope that it can be answered here though.
I have created a cron job which will execute a shell script every 2 minutes on my machine. However, the cronjob is not executing.
output of crontab -e command
2 * * * * /home/yuri/connector.sh >> /home/yuri/test.txt 2>&1
I have the cron daemon running:
ps aux | grep cron
root 944 0.0 0.0 19120 932 ? Ss 08:25 0:02 cron
1000 19619 0.0 0.0 13600 880 pts/2 S+ 21:50 0:00 grep --color=auto cron
The connector.sh shell script runs properly when I execute it manually, however when run through the cron job created above, it does not work.
I have redirected the output to a text file to know if something is going wrong while executing the cron job, but no such text file is created.
Your cron job isn't set to run every two minutes, it's set to run on the second minute of every hour. You might change it as follows:
*/2 * * * * /home/yuri/connector.sh >> /home/yuri/test.txt 2>&1
Running every 2 minutes should be given as
*/2 * * * * /home/yuri/connector.sh >> /home/yuri/test.txt 2>&1.
Does this work ?
I created a cronjob with the command crontab -e:
*/1 * * * * /var/lib/tomcat/webapps/ROOT/WEB-INF/scripts/test.sh
This file test.sh should be executed every minute. But it doesn't work.
If I run the script manually it works fine. So I think the problem is the cronjob not the script ;)
Are there any permissions or something else which block the cronjob?
Is the cronjob syntax correct?
Thx
For a start, you don't need the /1 if you want it done every minute. Just setting the minute field to * will do.
Next, you should place, as the first lines in your test script (though after the #! line if it's there):
env >/tmp/test.sh.dummy
set >>/tmp/test.sh.dummy
and see if that file shows up.
That will tell you if the script is running or not.
If it's not running, check to make sure cron itself is running:
pax> ps -ef | grep cron | grep -v grep
root 1048 1 0 08:45 ? 00:00:00 cron
(mine is).
If it is running, the most likely problem is that the environment under which cron runs your jobs is nowhere near the environment your shell gives you. Examine the differences between what was output to your /tmp/test.sh.dummy file and what your shell gives your when you execute env ; set.