Scheduling a Cron Job

Note that if you are wanting to schedule a script to run with Cron and execute SQLPLUS, you may have to make the script aware of the user environment variables like this:

#!/bin/sh
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
sqlplus -S perfstat/perfstat @query.sql > outfile.txt

To run a script with Cron automatically:


  1. Log in to the OS as the user you want to execute the job.
  2. Run "crontab -e" to edit the crontab configuration file
  3. Add a line to the configuration file to specify the info about the job.

The crontab file is organized like this:

* * * * * /path/for/CommandToBeExecuted
- - - - -
| | | | |
| | | | +----- day of week (0=Sunday, 1=Monday, ... ,6=Saturday)
| | | +------- month (1=Jan, ..., 12=December)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

Example 1: Run example1.sh every day at 10:30am and 10:30pm:

30 10,22 0 0 0 /home/example1.sh

Example 2: Run example2.sh Monday-Friday at 7:00pm:

* 19 * * 1-5 /home/example1.sh