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
Solved

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

Posted on 2010-09-14
11
2,472 Views
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
0
Comment
Question by:Alaska Cowboy
  • 7
  • 3
11 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
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.

wmp


0
 
LVL 1

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
0
 
LVL 1

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:
/slice6/imedw/code_non_compile/daily_load_tracker.ksh
or just ./daily_load_tracker.ksh
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

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

Expert Comment

by:woolmilkporc
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).

wmp
0
 
LVL 3

Assisted Solution

by:berniep
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.
0
 
LVL 1

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

#!/usr/bin/sh
####
# 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_ASK=NO
. oraenv
ORAENV_ASK=

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;
   exit
!

Open in new window

0
 
LVL 68

Accepted Solution

by:
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
or
.  $HOME/oraenv
I assume oraenv contains the requireded PATH setup, so sqlplus should be found in its correct location later.
 
 
0
 
LVL 1

Author Comment

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

Author Comment

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

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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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.:
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.

856 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