LinuxQuestions.org
Review your favorite Linux distribution.
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 09-16-2010, 12:44 PM   #1
Pricy
LQ Newbie
 
Registered: Sep 2010
Posts: 13

Rep: Reputation: 0
Angry Problems running cron jobs


I am very new in Linux and this is my first time creatign a cron job.

This is what I have

I created a test_backup file and put this in it.

Backup file

cd /export/home/Backups
tar cvf test test_backup

then a created a test_backup.cron with this code and saved it under /etc/cron.hourly folder as test_backup.cron

================================

#/bin/sh
5 * * * * /etc/cron.hourly/test_backups

======================================

went in the shell and typed
crontab /etc/cron.hourly/test_backup


and got a bad minute error and the cron job will not run.

changed the 5 * * * * to @hourly and still got the same error and the job wont run

what am I doing wrong.
 
Old 09-16-2010, 03:11 PM   #2
Steel_J
Member
 
Registered: Oct 2004
Location: Montreal, Canada
Distribution: Kubuntu 10.04, Mint 8 and Puppy 4.3.1
Posts: 355
Blog Entries: 1

Rep: Reputation: 31
/etc/cron.hourly is a directory in which you put files you would like to be executed "hourly".

Don't put scripts with cron syntax in them inside that folder. It is useless and contrary to the point.

What you need to do is simply put a copy of your "test_backups" script in there and give it execute permission like so :

Open a terminal and go to cron.hourly
Quote:
cd /etc/cron.hourly
then give permission*** to your script:
Quote:
chmod +x ./test_backups
***Make sure you are root or use sudo if you have Ubuntu variants.

This should work. Check back after an hour.

You can read this to learn more: http://www.redhat.com/docs/manuals/l...cron-task.html

Here is a quote from that page to help you understand
Quote:
As you can see from the /etc/crontab file, it uses the run-parts script to execute the scripts in the /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly files on an hourly, daily, weekly, or monthly basis respectively. The files in these directory should be shell scripts.

If a cron tasks needs to be executed on a schedule other than hourly, daily, weekly, or monthly, it can be added to the /etc/cron.d directory. All files in this directory use the same syntax as /etc/crontab.

P.S Some free advice. Create a signature with your system specifications and your Linux distribution. That way all your post will contain this information which is usefull for people trying to help you.

Last edited by Steel_J; 09-16-2010 at 03:16 PM.
 
Old 09-16-2010, 04:17 PM   #3
Pricy
LQ Newbie
 
Registered: Sep 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks!
 
Old 09-20-2010, 04:36 PM   #4
Pricy
LQ Newbie
 
Registered: Sep 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Ok I created a text file test_backups and saved it in the /etc/cron.hourly folder.

This is what I typed in the text file

====================
#!/bin/ssh

0 30 * * * tar cvf /export/home/Backups/test.tar /var/log/test.xlog

=======================================

I also did the following

chmod +x test_backups

crontrab test_backups

I am not getting any errors and the cronjob is not running.

What I am I missing

I am running RHAT 5.0.
 
Old 09-20-2010, 07:40 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
Try the following instead:
Code:
#!/bin/sh

tar cvf /export/home/Backups/test.tar /var/log/test.xlog
 
Old 09-21-2010, 12:22 AM   #6
Steel_J
Member
 
Registered: Oct 2004
Location: Montreal, Canada
Distribution: Kubuntu 10.04, Mint 8 and Puppy 4.3.1
Posts: 355
Blog Entries: 1

Rep: Reputation: 31
Like I said earlier.

Don't put a scipt with a cron job inside cron.houly folder. What this does is tell cron to run a cron job on a cron job.

That is like putting a wrapped gift inside a wrapped gift. Get it.

If you insist on doing your own precise cron job, add the line in crontab. Otherwise I would use this modified version of your script in cron.houly

Quote:
#!/bin/ssh

tar cvf /export/home/Backups/test.tar /var/log/test.xlog
 
Old 09-21-2010, 03:46 AM   #7
raviteja_s
Member
 
Registered: Jun 2010
Location: India
Distribution: Redhat
Posts: 68

Rep: Reputation: 1
Try it this steps:

1) */5 * * * * /home/cron.date

2) vim cron.date

#!/bin/bash

date +%T >> /tmp/con.log

:wq

3) cd /tmp/cron.log


output is shown here
 
Old 09-21-2010, 05:24 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
@Steel_J: as per preceding post to yours, 'sh' not 'ssh'
 
Old 09-21-2010, 08:22 AM   #9
cadd
LQ Newbie
 
Registered: Aug 2010
Posts: 16

Rep: Reputation: 0
Hi,

I want to run a c code once a day. I need to write a cron job for it.

I have modified my crontab using crontab -e

0 0 * * * root /home/abc/cprogram


Do I need to do anything else to run the code.
Regards,

Last edited by cadd; 09-21-2010 at 11:25 AM.
 
  


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
Cron jobs not running henrybg Linux - Enterprise 10 01-28-2013 11:23 AM
[SOLVED] Cron jobs not running saldon Linux - Server 2 01-08-2010 11:01 AM
cron is running but jobs aren't kalahari875 Mandriva 4 03-15-2006 04:47 PM
One user's cron jobs not running dcroxton Linux - Software 5 03-06-2006 04:33 PM
cron jobs not running scarr3d Linux - Software 7 05-25-2004 05:21 PM


All times are GMT -5. The time now is 08:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration