Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
11-28-2009, 08:57 AM
|
#1
|
Member
Registered: Jan 2007
Posts: 39
Rep:
|
Crontab is not working
Dear all
Here is the steps I've done. Please correct me if I made anything wrong. My cron job is not working
Code:
user@localhost:~> ls -lh test.dat
/bin/ls: test.dat: No such file or directory
user@localhost:~> date
Sat Nov 28 19:18:33 GMT+4 2009
user@localhost:~> crontab -e
crontab: no changes made to crontab
user@localhost:~> crontab -e
crontab: installing new crontab
user@localhost:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXkkSAid installed on Sat Nov 28 19:18:52 2009)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
19 19 * * * /bin/echo "test" >> /opt/user/test.dat
user@localhost:~> date
Sat Nov 28 19:18:56 GMT+4 2009
user@localhost:~> date
Sat Nov 28 19:19:02 GMT+4 2009
user@localhost:~> ls -lh test.dat
/bin/ls: test.dat: No such file or directory
user@localhost:~>
|
|
|
11-28-2009, 09:01 AM
|
#2
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
Quote:
user@localhost:~> ls -lh test.dat
/bin/ls: test.dat: No such file or directory
user@localhost:~>
|
are you in /opt/user/ ?
try
Code:
ls -lh /opt/user/test.dat
|
|
|
11-28-2009, 09:03 AM
|
#3
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Sure I'm there
Quote:
/bin/ls: /opt/user/test.dat: No such file or directory
user@localhost:~>
|
|
|
|
11-28-2009, 09:07 AM
|
#4
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
Do you have permission to write to /opt/user?
Take a look in the lofgfiles for errrors from cron.
|
|
|
11-28-2009, 09:12 AM
|
#5
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Yes, I 've permission on that folder as I can create a file there
Quote:
user@localhost:~> touch tet
user@localhost:~> ls tet
tet
user@localhost:~>
|
I opened /var/log/messages file and see the following lines:
Nov 28 19:18:52 localhost crontab[4279]: (user) END EDIT (user)
Nov 28 19:18:54 localhost crontab[4283]: (user) LIST (user)
Nov 28 19:19:01 localhost /usr/sbin/cron[4405]: (user) RELOAD (tabs/user)
What does it mean? There's no error
|
|
|
11-28-2009, 09:16 AM
|
#6
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
Could you post the output from
|
|
|
11-28-2009, 09:20 AM
|
#7
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Please see the output
Quote:
user@localhost:~> pwd
/opt/user
|
|
|
|
11-28-2009, 09:34 AM
|
#8
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
try
Code:
* * * * * /bin/echo "test" >> /opt/user/test.dat
It will run every minute
|
|
1 members found this post helpful.
|
11-30-2009, 01:43 AM
|
#9
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Thanks repo for your help. It's working for every minute, but not working for specific date and time. What's the reason?
|
|
|
11-30-2009, 02:38 AM
|
#10
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
Quote:
19 19 * * * /bin/echo "test" >> /opt/user/test.dat
|
should launch the crontab at 7h19 pm
|
|
|
11-30-2009, 02:51 AM
|
#11
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Could you explain why the following cron is not working?
Quote:
user@localhost:~> date
Mon Nov 30 13:17:43 GMT+4 2009
user@localhost:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXvnPD7i installed on Mon Nov 30 13:17:37 2009)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
18 13 * * * /bin/echo "test" >> /opt/user/test.dat
user@localhost:~> date
Mon Nov 30 13:18:02 GMT+4 2009
user@localhost:~> ls -lh test.dat
/bin/ls: test.dat: No such file or directory
user@localhost:~> ls -lh /opt/user/test.dat
/bin/ls: /opt/user/test.dat: No such file or directory
user@localhost:~>
|
|
|
|
11-30-2009, 02:56 AM
|
#12
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Interesting issue, when I change the cron to run on every minute, it works... Where is the problem??
|
|
|
11-30-2009, 05:27 AM
|
#13
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
crontab -e edits a file in cron's spool folder, where all users' cron jobs are stored.
Each minute, cron will check the spool folder for updates and ingest them if found.
So, if you schedule a job to run on minute 18, while you are on minute 17, it is possible that
cron will miss your update.
Try leaving 2-3 minutes between the time when you change the crontab and the job execution time,
allowing cron to detect and incorporate the update.
Note: this is also why you can't schedule cron jobs to the second (or millisecond) levels: cron only
checks for updates once per minute. Have a look at the cron jobs scheduled in /etc/cron*, like /etc/crontab.
|
|
1 members found this post helpful.
|
11-30-2009, 06:30 PM
|
#14
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,397
|
Good advice. Also, if cron has an issue, it'll usually email the cron job owner or root with a summary.
Try mail or mailx at the cli as you and root to see if it said anything.
|
|
|
12-01-2009, 06:09 AM
|
#15
|
Member
Registered: Jan 2007
Posts: 39
Original Poster
Rep:
|
Thank you guys. I've solved it using and investigating the cron log. There I saw that it doesn't run for the first time, it just RELOAD, but runs for the next time
I have another question, how can I get the current date and time when my cron will run? I configured it, and now want to know the current dates when it will run "without running it"
Thanks in advance
|
|
|
All times are GMT -5. The time now is 09:20 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|