[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cron Job - Correct Syntax

Posted on 2002-03-26
4
Medium Priority
?
532 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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 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