Solved

Cron Job - Correct Syntax

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
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.:

708 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

15 Experts available now in Live!

Get 1:1 Help Now