How to run a cron job at 9am, 1pm, 4pm

Posted on 2010-09-14
Last Modified: 2013-12-21
I'm pretty comfortable with cron jobs but wanted to check since I am going to edit the production file and this will be my first time to do so . . .

I have a new job that is supposed to run at 9am, 1pm, 4pm, so is this the right command ?

0 9, 13, 16 * * * /slice6/imedw/code_non_compile/daily_load_tracker.ksh 1>/dev/null 2>&1

And what is this: 1>/dev/null 2>&1
- it's at the end of every command in the cron file
Question by:Alaska Cowboy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
LVL 68

Assisted Solution

woolmilkporc earned 100 total points
ID: 33675109
Don't leave spaces around the commas!

0 9,13,16 * * * /slice6/imedw/code_non_compile/daily_load_tracker.ksh 1>/dev/null 2>&1

1>/dev/null 2>&1

means: suppress all output (stdout (1) and stderr (2))

else a possible output would be emailed to the owner of the crontab.



Author Comment

by:Alaska Cowboy
ID: 33675134
ok, good thing I checked ! thanks.
I'll leave this open until tomorrow, when I can put it in Prod

Author Comment

by:Alaska Cowboy
ID: 33686532
it didn't work, I tried it several times (with different times),
 # Run missing daily loads job, that sends e-mails, Sept 2010, W. Peck
52 16 * * * /slice6/imedw/code_non_compile/daily_load_tracker.ksh 1>/dev/null 2>&1
the job runs correctly if I run it manually, like this:
or just ./daily_load_tracker.ksh
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:Alaska Cowboy
ID: 33686565
I was expecting an e-mail, but nothing.
LVL 68

Expert Comment

ID: 33687168
Where should that email come from?

Does daily_load_tracker.ksh contain a mail command?

If it doesn't - please remember what I wrote above: There will be no automatic email when the output of the script is suppressed by redirecting it do /dev/null!

You can have cron send the output to you (as the owner of the crontab) by removing the redirection:

0 9,13,16 * * * /slice6/imedw/code_non_compile/daily_load_tracker.ksh

or you can incorporate a mail command into the cron line itself:

0 9,13,16 * * * /slice6/imedw/code_non_compile/daily_load_tracker.ksh | mailx -s "load tracker output" williampeck@somedomain.tld
If the script does conatin a mail command, however, and you didn't get an email nonetheless - could it be that the script would rely on some environment variables or PATHs which are present in a normal shell, but not under cron?
Please be aware that shell initialization profiles such as $HOME/.profile are not executed by cron, so you must set all needed variables inside the script!
This includes the required PATH if you don't call each and every executable by its full path (except for those in /usr/bin, this path is always present).


Assisted Solution

berniep earned 25 total points
ID: 33687641
by the way, how did you make the change?

If you edited the crontab file using an editor (vi /var/spool/cron/crontabs/root), the change won't be picked up unless you restart cron (I think that kill -HUP on the cron PID will do)

The alternative is to use the "crontab -e" command, which loads the cron file into $EDITOR, then loads in the changes when you save & exit AND warns you of syntax errors.  HTH.

Author Comment

by:Alaska Cowboy
ID: 33691268
woolmilkporc, thanks.
the script calls and oracle stored procedure which sends the e-mail, so I don't think the re-direct is the issue (see snippet).
so when I run the job manually it works but I'm not seeing cron submit the job
berniep, I did "crontab -e", then after saving, would open again to see if the changes were made, and they are there. Although when I save, it says "/tmp/crontabh4EtEa" 34 lines, 2054 characters

# Program Name: daily_load_tracker.ksh
# Author: W. Peck
# Created: Sept 2010
# Purpose: List missing daily loads each day (job will be run at 9am, 1pm, and 4pm)
# Set up Unix Trace
set -x

dateparm=`date "+%d-%b-%Y-%T"`
export temp_output=/slice6/imedw/fix_output

# Set up Oracle environmental variables
export ORACLE_SID=edwprd02
. oraenv

time_start=`date "+%x %X"`

# run the job
sqlplus -s / << ! 1> /tmp/prd_cdr$$ 2>&1
   whenever sqlerror exit 99 rollback
   set pause off
   set pages 0
   set feedback off
   set trimspool on
   set echo off
   set termout off
   exec edw_util_api.check_daily_loads;

Open in new window

LVL 68

Accepted Solution

woolmilkporc earned 100 total points
ID: 33691664
I think it's here .(line 22)
. oraenv
There is no PATH to your current directory (which is $HOME) under cron.
So best add the full path to oraenv in line 22, or use $HOME/oraenv if applicable.
.  /full/path/to/oraenv
.  $HOME/oraenv
I assume oraenv contains the requireded PATH setup, so sqlplus should be found in its correct location later.

Author Comment

by:Alaska Cowboy
ID: 33691734
wmc, ok, I'll try that, thanks.

Author Comment

by:Alaska Cowboy
ID: 33726463
yes, that's it, crontab doesn't know the path, thanks.

Author Comment

by:Alaska Cowboy
ID: 33726482
even though I closed this with points, it's still in a pending status. It should close in 4 days, there's a bug EE is working on.

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

Suggested Solutions

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

752 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