Operating System - HP-UX
1753783 Members
6899 Online
108799 Solutions
New Discussion юеВ

Re: New to UNIX, how do I create a scrip and a cron job?

 
SOLVED
Go to solution
Victor_138
Regular Advisor

New to UNIX, how do I create a scrip and a cron job?

I'm new to the Unix world and need to create a script to shutdown Oracle at 9:00pm and restart it at 5:00am. Also need to create a cron job to execute that script on a daily basis.

Any pointers?
23 REPLIES 23
Rick Garland
Honored Contributor

Re: New to UNIX, how do I create a scrip and a cron job?

At the basic level you can use the dbstart and dbshut scripts provided by oracle. Beware, depending on version you may have trouble with these scripts.

There are other issues to be aware of as well such as the type of environment you are in. You are making a blanket request and not all solutions will fit your needs.

As to cron;

00 21 * * * /dbshut
00 05 * * * /dbstart

This will execute dbshut at 2100 hrs daily
This will execute dbstart at 0500 hrs daily.

Again, this is a simple version of the syntax.
Victor BERRIDGE
Honored Contributor

Re: New to UNIX, how do I create a scrip and a cron job?

Hi,
I believe you already have a script...
Look in /sbin/init.d/ for something oracle related...
Does you oracle instance start at bootup?
If yes then at which runlevel - most chances to be 3, so look in /sbin/rc3.d/ a Sxxxoracle or something like

All this to say you have the script you now just need to create a cron file
man cron for a start
Then check with the sysadmin if you have the rights to create/use cron


All the best
Victor
Victor_138
Regular Advisor

Re: New to UNIX, how do I create a scrip and a cron job?

I did found an Oracle related file on /sbin/init.d. How can I determine the runlevel of the file?
Victor BERRIDGE
Honored Contributor

Re: New to UNIX, how do I create a scrip and a cron job?

To know your actual runlevel:
who -r

To see how your script is launched, you should find in /sbin/rc2. a Kxxxfile linked to your oracle file in /sbin/init.d the same goes for rc3.d but this time you have to look for a Sxxxfile.


All the best
Victor
Victor_138
Regular Advisor

Re: New to UNIX, how do I create a scrip and a cron job?

On /sbin/rc2.d I found S910oracle linked to oracle in /sbin/init.d but on /sbin/rc3.d was nothing that I could relate to Oracle.

How this works? Do I have to create the file in /sbin/init.d and link it to /sbin/rc2.d?

I'm kind of lost here.

lawrenzo
Trusted Contributor

Re: New to UNIX, how do I create a scrip and a cron job?

Ok you are looking in the /sbin/init.d/oracle script to determine what options are required to stop and start oracle.

the rc.2 directory means that when the system is booted oracle starts at run level 2, the system is up at run level 3 (/sbin/rc.3/) and a whole bunch of other programs / process will be started at this level as the server is booted.

You want to stop and start oracle via cron, once you find the options from the oracle script add the following to cron:

00 21 * * * /sbin/init.d/oracle stop
00 05 * * * /sbin/init.d/oracle start.

This should do the trick.

hello
Nguyen Anh Tien
Honored Contributor

Re: New to UNIX, how do I create a scrip and a cron job?

1, Allow oracle user run crontab by modifying /var/adm/cron/cron.allow
root
oracle
:wq!#then save and exit
2, get attached file for scripts
3, su - oracle
[server:/] su - oracle
exit crontab
#crontab -e

[server:/home/oracle] crontab -e
# minute hour date month weekday command
00 21 * * * sh /home/oracle/scripts/Ora_shutdown.sh
00 05 * * * sh /home/oracle/scripts/Ora_start.sh

that's all
tienna
HP is simple
Victor BERRIDGE
Honored Contributor
Solution

Re: New to UNIX, how do I create a scrip and a cron job?


>On /sbin/rc2.d I found S910oracle linked to oracle in
>/sbin/init.d but on /sbin/rc3.d was nothing that I could relate to Oracle.
>
>How this works? Do I have to create the file in
>/sbin/init.d and link it to /sbin/rc2.d?

at run level 2 when the system is booting it looks sequentialy for files to start and
called S0XXXfile and gives the start option
at level 1 when system i beeing brought down
It look for Kxxxfile and give stop argument

I believe your oracle file should be in rc2.d for Kxxx and rc3 for SYYY

But its up to you...

Here is an example of what we do for start/stop scripts for oracle:

#!/usr/bin/ksh
export ORACTI_EXPLOIT=/opt/oracle/admin/exploit
export PATH=$PATH:/usr/bin:$ORACTI_EXPLOIT/proc


case "$1" in
start_msg)
echo "Start Oracle"
;;
stop_msg)
echo "Stop Oracle"
;;
start)
$ORACTI_EXPLOIT/proc/db_start
su - oracle -c $ORACTI_EXPLOIT/proc/net_start
;;
stop)
su - oracle -c $ORACTI_EXPLOIT/proc/net_stop
$ORACTI_EXPLOIT/proc/db_shut
;;
*)
echo "usage: $0 {start|stop}"
#rval=1
;;
esac

----------------------------------------
Here is an extract of a cronfile the way I do...
Notice I put conrfiles in a structure /sm/cron with big comments on the syntax
and usage since I have poor memory...

This leaves a way to modify the the cronfile by getting it at its location.
TO load it is simply crontab cronfile.root
--------------------------------------

# /sm/cron/cronfile.root
# crontab file for the super-user.
#
# ==========================================================================
# F O R M A T
# ==========================================================================
# Minute Hour Month_Day Month Weekday Command
# (0-59) (0-23) (1-31) (1-12) (0-6)*0=sun run-string
# * = in any crontab field represents all legal values.
# Therefore, to schedule the ps(1) cmd to execute at 5:10pm on every
# friday and monday during june, july, august, you would make an entry
# in your crontab fithe that looks like this :
# 10 17 * 6,7,8 1,5 ps>>psfile 2>&1
# The 2>&1 redirects any error msg to the file psfile.
# ==========================================================================

# archive annuelle de l export le 3 dimanche de janvier chaque annee
#00 04 * 1 0 /sm/bin/archive_annuelle >>/sm/log/archive_ann.er 2>&1

# log kernel diagnostic messages every 10 minutes
05,15,25,35,45,55 * * * * /usr/sbin/dmesg - >>/var/adm/messages
#05,15,20,35,45,55 * * * * /usr/bin/ulimit >>/var/adm/ulimit.cron 2>&1
#05,15,21,35,45,55 * * * * /usr/bin/ulimit -a >>/var/adm/ulimit.cron 2>&1
07,17,27,37,47,57 * * * * /var/adm/root/clean_tmp>>/var/adm/cleantmp.log 2>&1

# Sample nightly invocation of calendar. If you wish to run calendar,
# just uncomment the next line.
#0 4 * * * exec /usr/bin/calendar -
# ==========================================================================
# effacer les disques temporaires
# ==========================================================================
#
00 23 * * 1,2,3,4,5 /sm/cron/bin/effacer>>/sm/cron/log/efface.log 2>&1
05 23 * * 1,2,3,4,5 /sm/cron/bin/clean_xprt_s>/sm/cron/log/cleanXs.log 2>&1

# ============================ E N D =======================================

NOw user who are allowed to use cron or at cmd ar defined in files in /var/adm/cron:
-r--r--r-- 1 bin bin 18 Nov 14 2000 at.allow
-r--r--r-- 1 bin bin 31 Feb 12 2003 cron.allow
-rw-r--r-- 1 root root 1041016 May 18 10:47 log
in cron .allow and at.allow you give the users you are allowed:

:/var/adm/cron $ more cron.allow
root
adm
vbe
uucp
prod
rdm
dupont



-----


Courage!!

All the best
Victor
Suraj Singh_1
Trusted Contributor

Re: New to UNIX, how do I create a scrip and a cron job?

I don't really see why would you require to shut and start Oracle every evening and morning.

As far as oracle startup script exists in /sbin/init.d and is linked to /sbin/rc2.d.. it should suffice.

Regards
What we cannot speak about we must pass over in silence.