Solved

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

Posted on 2010-09-14
11
2,403 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

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

Expert Comment

by:woolmilkporc
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Assisted Solution

by:berniep
berniep earned 25 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
wmc, ok, I'll try that, thanks.
0
 
LVL 1

Author Comment

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

Author Comment

by:Alaska Cowboy
Comment Utility
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

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…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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.:

728 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

12 Experts available now in Live!

Get 1:1 Help Now