Discussion Locked

problem with crontab

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a shell script in cron that calls "sqlplus". Whenever this script is run by cron, it encounters this error-> sqlplus: not found. But if I manually execute the script, it executes successfully.

Is there something I need to include in my script, like an environment variable or something?

9 replies

by vanwill

probably you are executing the sqlplus script from the root cron. And when you execute it from the command line you are not logged on as root.
so you environment variables are not correct when executing it from the cron.
Anyway it has something to do with users and authorizations.

by minette

Is it possible that what I see listed, after I enter the command "crontab -l", are not my own cron jobs but the root's?

Btw, I'm not logging in as root. I'm actually using the user "oracle" which is the owner of the sqlplus program.

by dave4e2open

The CRON root 'owner' is trying to execute the SQL routine in a sub-directory that is not part of its path.
Either relocate the scripts to the root path or be sure to redirect the cron root to your sub-directory tree to find the proper sub-program.
Also, the cron root owner may not have the same SQL rights that you do when you login. So even once cron finds the SQL routine, it may not have SQL read rights.
Hope this helps.
Dave

by minette

Isn't it that cron ownership depends on who created the cron jobs? Are you saying that cron is owned by only one user and that is the "root"? And so, if I enter the command "crontab -l", I will see the list of jobs that I entered in cron, but I do not really own these cron jobs?

I've also tried including the path of sqlplus in the shell script, but still, it didn't work :-(

by dave4e2open

From what I remember, the cron daemon is owned by the root. Cron executed files are stored in the /etc/crontab file. You need to have superuser privedges to modify the crontab file or a file within the /etc/crontab directory.
You can have cron execute a series of commands including a cd to where you keep your executables or .sh files.
crontab -l will simply list the programs in your crontab directory but crontab -e [yourfile] will allow you to edit and enter the commands for your master scripts.
If you are using cron to execute a program/routine at a given time/frequency, cron will not login with your id of choice. So it will need to own or have permission to execute your routines on its own.
Experiment; Try to set the permission bits of sqlplus to give the 'world' execution rights. If cron finds it this way, then your problem is permission and not directory location.
Dave

by prefbid ii

The problem you are describing is normally in the shell. The way the system works is that cron is launched having "inherited" no login shell, whereas you do inherit from your login shell when you run the script interactively. So in cron your PATH variable and other environment variables are not set and the script can not find the executable.

The way around this is to explicitly state the path to the executable; e.g., /usr/local/bin/sqlplus or wherever it is located.

There are other waysaround this, but I find that it is always best to put the full path in the shell (it is easier to debug later when someone messes with the program and moves the executable).

Good practice is to list the executable with the path as an environmentvariable near the top of the shell -- but that is just a matter of programming style.

by minette

Thanks for all the suggestions and explanations :-)

I checked the permissions on sqlplus and everybody is granted the execute right on it.

Then, I edited my shell script to put in the full path of sqlplus.

Despite these, I still encounteredan error (which was now different from the previous error):

Message file sp1.msb not found
Error 6 initializing SQL*Plus

If you could still give me explanations on how this error came about or suggestions on how to work around it, please do so.

Thanks again.

by prefbid ii

You still have a path error inside your script. You have to realize that when the script is executed by cron, it reads no (none, nada) profile file -- neither your personal one nor any global one that may exist on your system.

I'm not familiar with sqlplus, but from the symptoms, I would suggest that you look in your .profile file and look for an environment variable that has something to do with sql. Whatever that environment variable is, copy it inside your script (include the execute statement if needed). Examples to look for would be a "SQLLIB=" or similar.

If that does not work, find where sp1*.msb is located on your system (e.g., /opt/sql1/lib) and then look in your .profile file to see which environment variable contains that directory. Then copy that environment variable into your script.

by dave4e2open

Perhaps there is something in the .profile of the logon used to execute the sqlplus.

If your admin has created a new application logon for this process, have the etc/.profile set up using your test .profile as a template. That way any env variables uses to give you rights to the Oracle sql fetch will be replicated for your cron executed scripts.

This discussion is closed to new replies.