LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-28-2009, 08:57 AM   #1
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Rep: Reputation: 15
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:~>
 
Old 11-28-2009, 09:01 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
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
 
Old 11-28-2009, 09:03 AM   #3
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
Sure I'm there

Quote:
/bin/ls: /opt/user/test.dat: No such file or directory
user@localhost:~>
 
Old 11-28-2009, 09:07 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Do you have permission to write to /opt/user?
Take a look in the lofgfiles for errrors from cron.
 
Old 11-28-2009, 09:12 AM   #5
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 11-28-2009, 09:16 AM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Could you post the output from
Code:
pwd
 
Old 11-28-2009, 09:20 AM   #7
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
Please see the output

Quote:
user@localhost:~> pwd
/opt/user
 
Old 11-28-2009, 09:34 AM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
try
Code:
* * * * * /bin/echo "test" >> /opt/user/test.dat
It will run every minute
 
1 members found this post helpful.
Old 11-30-2009, 01:43 AM   #9
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
Thanks repo for your help. It's working for every minute, but not working for specific date and time. What's the reason?
 
Old 11-30-2009, 02:38 AM   #10
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
19 19 * * * /bin/echo "test" >> /opt/user/test.dat
should launch the crontab at 7h19 pm
 
Old 11-30-2009, 02:51 AM   #11
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
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:~>
 
Old 11-30-2009, 02:56 AM   #12
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
Interesting issue, when I change the cron to run on every minute, it works... Where is the problem??
 
Old 11-30-2009, 05:27 AM   #13
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
Old 11-30-2009, 06:30 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,397

Rep: Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777Reputation: 2777
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.
 
Old 12-01-2009, 06:09 AM   #15
Ejdaha
Member
 
Registered: Jan 2007
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
crontab not working ankitsagwekar Red Hat 1 08-08-2008 05:45 AM
Crontab not working Zeno McDohl Linux - Newbie 1 06-05-2007 06:52 PM
Crontab Not working appropriate? roclok Linux - Software 9 06-15-2006 11:34 PM
crontab not working durgap Linux - General 6 09-01-2005 02:38 PM
crontab nor working navaladi Mandriva 11 01-17-2005 06:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration