Alaska Cowboy
asked on
How to run a cron job at 9am, 1pm, 4pm
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_com pile/daily _load_trac ker.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
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_com
And what is this: 1>/dev/null 2>&1
- it's at the end of every command in the cron file
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_com pile/daily _load_trac ker.ksh 1>/dev/null 2>&1
the job runs correctly if I run it manually, like this:
/slice6/imedw/code_non_com pile/daily _load_trac ker.ksh
or just ./daily_load_tracker.ksh
# Run missing daily loads job, that sends e-mails, Sept 2010, W. Peck
52 16 * * * /slice6/imedw/code_non_com
the job runs correctly if I run it manually, like this:
/slice6/imedw/code_non_com
or just ./daily_load_tracker.ksh
ASKER
I was expecting an e-mail, but nothing.
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_com pile/daily _load_trac ker.ksh
or you can incorporate a mail command into the cron line itself:
0 9,13,16 * * * /slice6/imedw/code_non_com pile/daily _load_trac ker.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
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_com
or you can incorporate a mail command into the cron line itself:
0 9,13,16 * * * /slice6/imedw/code_non_com
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wmc, ok, I'll try that, thanks.
ASKER
yes, that's it, crontab doesn't know the path, thanks.
ASKER
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.
ASKER
I'll leave this open until tomorrow, when I can put it in Prod