Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-14
11
Medium Priority
?
2,645 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 100 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 400 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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 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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

824 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