Hi
Can some one please look this over for errors? I am trying to run it on cron but it doesn't seem to want to run.
The names have been changed to dummies.
#!/sh/bash
#script to keep location on line chunking. it checks every four hours by #cron to see if it is working.
#if it is not running then start it up again.
export ORACLE_HOME=/app/oracle/product/11.2.0/dbhome_1
export ORACLE_HOSTNAME=redhatora03
export ORACLE_SID=sid_name
export PATH=/app/oracle/product/11.2.0/dbhome_1/bin:/home/oracle/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin
cd /home/oracle/monitor
export CURRTIME='date+%m/%d/%y:%H:%M:%s'
echo ${CURRTIME}
if $? = 0 then #this checks the return of the last executed statment.
null #0 for "ok" and a non zero number for an error.
else
nohup sqlplus schema_owner/passwd@sid @/home/oracle/chunker_loc/chunker.sql > sidcronchunk.out &
fi
Is cron mailing you any errors? If cron can't tell you the error messages, try trapping them with exec 2> /tmp/myerr at the beginning of your code. If /tmp/myerr doesn't appear at all, your cron line isn't being run at all. Otherwise, its contents may be helpful.
... and the "if" statement contains basic syntax errors. However the entire "if" statement appears to be pointless because it will just check the reply from the preceding "echo" command which will always be value zero.
I would remove the "if" statement completely and just invoke sqlplus with its full path.
The reasoning I am trying to corral this is as follows.
We have two databases one here and the other in Europe replicating. There is one large table over 8 mil rows that has fallen way behind and because of the connectivity issues doing inserts directly into a staging table seems easier.
Anyway every day I kick off an insert statement but can't continually monitor the progress. What I wanted to do thru the cron was determine if that statement was still running every 4 hours. If it was running then do nothing. If it wasn't running then kick the job off again.
This is what I was trying to accomplish with this script. I am new at this and reading every night about this scripting.
This script would make my life easier at work because I actually have 3 other locations that needs this support.
The normal method is to create a semaphore file in a work directory for the duration of the run and delete that file at the end of the run. In this design we do not want to background the sqlplus line because we need to execute a command after the sqlplus line finishes.
In the cron job, test for the presence of the semaphore file. If it exists, then exit silently. If it does not exist, create the semaphore file and delete it after a successful run.
This design allows you to run the cron at a much more frequent interval because you can be sure that you will never execute two of these jobs concurrently.
Hope this helps.
Thanks for the advice. This evening I did some research on syntax which I was in dire need of knowing and found a good tutorial. In it is showed how to use the $? in a if statement. So I am going to review my syntax to understand it before I drive you guys/gals crazy with my questions.
I will present another type of command to be reviewed here if there is a problem with it. At work I will test it until I get frustrated. Then you will hear from me again.
I don't like depending on other people to do my job here so I need to get up to speed. I really need to get this stuff in my head because I am around these servers all day long.
Again thanks to all that helped me. I will get back to you.
Usually there is no need to use $?, you use commands and if-statements directly. It's there for the odd situations where you must save a return value for later or some such.
You should know that the PATH environment variable will likely be different for cron jobs than for your terminal session. Include a PATH= statement in your cron script.