Solved

Cron Job - Correct Syntax

Posted on 2002-03-26
4
499 Views
Last Modified: 2012-08-13
I need to run a cron job as root.  I thought I could just add the job to the existing /etc/crontab file to have it run.  I added the job - but it doesn't run!  Here is the existing crontab file and then the line I added to it:

** EXISTING **
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
# sysstat
0 * * * 0,6 root /usr/lib/sa/sa1 600 6 &
5 19 * * * root /usr/lib/sa/sa2 -A &

** I ADDED THIS LINE UNDER "# sysstat" **
5 0 * * * /root/scripts/http_log_archive.sh

Is there something wrong with the syntax?  Why do the other lines in the existing cronttab have "root" before the script they are calling and what are the characters (-A &, 600 6 &) at the end of some of the scripts used for?

My script runs fine from the command line.

Thanks,

Lisa
0
Comment
Question by:lphillips120898
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 100 total points
ID: 6896385
That's a Linux systme and you are adding your job to a special crontab. I think it'll work if you make your line read:

5 0 * * * root /root/scripts/http_log_archive.sh

Assuming that your script starts with the line #!/bin/sh and that the file is executable (mode 755).

That crontab is special in that it doesn't follow what's documented in the man page for crontab. The difference being that the user the command should be run as (root) must be specified. You could use your command as is by executing (as root) 'crontab -e' and entering your line. That gains you access to a conventional crontab.

Those things at the ends of some of the lines are simply arguments to commands ( '-A', '600 6') and the & says that the job is to be run in the background.
0
 

Author Comment

by:lphillips120898
ID: 6897059
I've added the line you suggested to the /etc/crontab and I'll see if it runs tonight.

I have a question about something you said:

You could use
your command as is by executing (as root) 'crontab -e' and entering your line. That gains you access
to a conventional crontab.

If I were to run the command you suggested above would it add an entry to the /etc/crontab file - OR - would it write this to some other file to be executed?  If users have their own "crontab" where is that stored?

Thanks,

Lisa
0
 
LVL 40

Expert Comment

by:jlevie
ID: 6897114
Normal crontabs are stored, per user, in /var/spool/cron. Unless a user has created a crontab that directory will be empty.
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 6897344
Also, editing the file is not sufficient.  The cron daemon needs to be kicked.  The normal way to do this is to load new crontab files with the 'crontab' command, which also eliminates the whole issue of figuring out exactly what file you need to modify.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question