Solved

Cron Job - Correct Syntax

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now