Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron job / $ variable

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
Since I a new to unix probably unix fans will able to crack this problem which I am facing.

I want to execute an oracle export through a cron.
I make the entry correctly . 40 15 * * * exp_file_name.
But it doesn't execute at all.
at command prompt if I run the exp_file_name , it runs perfectly fine.
This export has to be run not as a root user but as an ordinary user.
there is no mention of this user in cron/allow or cron/deny.

What should I do in order to run this file through the cron.
moreover if the entry is done the cron/allow how does it look.

Any suggestions are welcome.

I have some users in oracle mentioned as ops$harry . that way if harry logs in the unix he will be able to log in to oracle (sqlplus) with login as / no need of giving a username and password once again.

The problem I am facing is if harry wants to take an export of the oracle database then a file is made which is kept in cron.

the file is given below.

exp userid=ops$harry/password_of_harry full=y

When i execute this file it gives me an error say harry variable not defined.
It is true that there is no envirnoment variable defined as harry.
But I want to do this export done by the user ops$harry of oracle.
how can make unix understand that this the user of oracle and not a envirnoment variable on unix.


 
john_ken,

I am guessing the environment in which the command works is not the same as the root environment .. some questions ...

1. Are you running the job as part of the root cron?

2. You should really include the full pathname of the command file in the crontab command, i.e. 40 15 * * * /mypath/commandfile

3. If you want to run as a root cron, you may have to set up a suitable environment for the script to run. This can be done by including the variables in the script, or by executing a .profile/.login at the beginning of the script.

4. If want the script to run in cron as a particular user, you can add that users login name to the cron.allow file. Bear in mind though that (I think) if a cron job runs as a particular user, that users .profile/.login does not automatically come into effect .. you still have to explicitly invoke it.

A lot of options there ... maybe if you can narrow down exactly what you want to achieve, we can look at it a bit more.

Regards,

Greg.
[sig][/sig]
 
Notes:

1. If you have a user [tt]ops$harry[/tt] inside Oracle, that doesn't imply you have a unix user with that name.
2. If you want to run the jobs like user [tt]ops$harry[/tt] (and this is a unix username) then try to:

a. create an empty [tt]/var/adm/cron/cron.deny[/tt] (allowing cron use to all users) or a [tt]/var/adm/cron/cron.deny[/tt] with a line with [tt]ops$harry[/tt] in it (allowing cron use to ops$harry).
b. su to user ops$harry using
[tt]su - 'ops$harry'[/tt]
using single quotes and giving the correct password for user [tt]ops$harry[/tt]
c. edit the cron tab for user [tt]ops$harry[/tt]
[tt]crontab -e[/tt]
include the line
[tt]40 15 * * * /complete/path/to/command/file[/tt]
Remember to use the complete path and don't assume the environment variables are defined... then if you need some variable define it inside the command file (if it's a script file).
d. wait and test (A mail will be received by user [tt]ops$harry[/tt] when cron executes (or try to) the job.

I hope it works... [sig][/sig]
 
Dear Greg,

I don't want to run this cron as a part of the root cron.

only one variable $PATH would be required as part of the "harry" user in unix. how do I include this PATH. Is it just by stating it.
setenv $PATH /oracle/bin:pATH

or is it something else.

I will include the name harry in the cron.allow and test it

Thanks,
John_ken

Dear Elgis,

harry is the unix user and ops$harry is the oracle user . Both of them are present on my system.

Thanks,
John_ken.

Greg and Elgis kindly get back to this link as I will post the result of your suggestions. again.
 
To add PATH, you can either ..

a) define PATH in the script being executed

or

b) execute the profile of user harry in the script being executed ..

in ksh, the command is . .profile
csh uses .login, so I guess it would be . .login

Greg. [sig][/sig]
 
Dear Greg and Elgis,

After performing all the tips provided , still I am not getting through.

Hence I am performing the jobs by the root user

10 15 * * * su - harry /path_of_the_file/file.sh


It is working fine.
But there will always be a curiosity as to why it didn't work the earlier

Thanks a million for your help.
john_ken
 
You may have a cluse in the /var/mail folder as cron generaly mails errors unless you redirect output. [sig]<p>Ged Jones<br><a href= > </a><br>Top man[/sig]
 
You may want to try
exp userid=ops\$harry/password_of_harry full=y
or
exp userid='ops$harry/password_of_harry' full=y

Tony ... aka chgwhat
tony_b@technologist.com

When in doubt,,, Power out...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top