Solved

Cron Job - Correct Syntax

Posted on 2002-03-26
4
508 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

820 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