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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assuming a profile while running a script from cron

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
Can I confirm that scripts run from cron will take root authority?

Futhermore, would it simply be a case of
su - oracle
at the begenning of the script to run with an alternative authority?

Thank you in advance
 
Cron really runs in a minimal environment, that's why many scripts fail if run from cron, but work perfectly from the command line. It is adviseable to set explicit PATH variables etc in a script to be run using cron to avaoid this problem. As to syntax, my usual entry in cron would be something like:

su - oracle -c "/path/to/script"

Hope this helps.
 
Thanks Ken. And would I be correct to say that since cron has higher authority than oracle, it would not await a password?
 
Yes, if the crontab you're using belongs to root, no password would be required.
 
If you run it from root's crontab it will runs as user root.

Ken's advise is 100% right, usually I would add the environment stuff to the script if so required, a good example would be the Java class path in some of my cases.

IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
MS Certified Windblows Rebooter
 
If you are wanting the cron job to run under user oracle, then the sensible place to put it is in oracle's cron.

That gets rid of the whole need to do an su in the 1st place.

In the script make sure everything is explicitly defined to ensure that it gets picked up. If you are lazy you can put a

. ~/.profile

at the beginning of the script to run the user's .profile file ( dont forget the ". " before ~/.profile

There is no reason to put these in the root cron and do a su, they will work just as well from the user's own cron file

Dave
 
Dave:

Thanks for that.

I did not even know oracle had it's own cron (I am very new to Unix, AIX, Oracle).

Question I have now is how do I access Oracle's cron?


 
Each user has it's own cron available.

Sign on as that user e.g oracle and type

crontab -e

to edit

crontab -l

to list


--
| Mike Nixon
| Unix Admin
|
----------------------------
 
I still get a mail for root denoting problems: (although it appears to work!)

Message 1:
From daemon Fri Sep 19 16:10:14 2003
Date: Fri, 19 Sep 2003 16:10:13 -0500
From: daemon
To: root

stty: tcgetattr: A specified file does not support the ioctl system call.
------------------------------------------
####### ###### ####### # ### # #
# # # # # # # # ## #
# # # # # # # # # # #
# # ###### # # # # # # #
# # # # # ####### # # # #
# # # # # # # # # ##
####### ###### # # # ### # #

### ####### ##### ######
# # # # # #
# # # # #
# ##### ##### ######
# # # #
# # # # #
### # ##### #

##### ####### # # ####### ###### ####### #
# # # # ## # # # # # # #
# # # # # # # # # # # #
# # # # # # # ###### # # #
# # # # # # # # # # # #
# # # # # ## # # # # # #
##### ####### # # # # # ####### #######

####### ### # #######
# # # #
# # # #
##### # # #####
# # # #
# # # #
# ### ####### #######

/home/oracle/IFSPtoIFSD/copy1off.unix[45]: sqlplus: not found.
------------------------------------------
##### # # # # ####### ###### ####### # # # #
# # # # # # # # # # # # # # ## #
# # # # # # # # # # # # # # # #
##### ####### # # # # # # # # # # # # #
# # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # ##
##### # # ##### # ###### ####### ## ## # #

### ####### ##### ######
# # # # # #
# # # # #
# ##### ##### # #
# # # # #
# # # # # #
### # ##### ######

/home/oracle/IFSPtoIFSD/copy1off.unix[78]: sqlplus: not found.
------------------------------------------
###### ####### # ####### ####### #######
# # # # # # #
# # # # # # #
# # ##### # ##### # #####
# # # # # # #
# # # # # # #
###### ####### ####### ####### # #######

### ####### ##### ######
# # # # # #
# # # # #
# ##### ##### # #
# # # # #
# # # # # #
### # ##### ######

------------------------------------------
##### ###### ####### # ####### #######
# # # # # # # # #
# # # # # # # #
# ###### ##### # # # #####
# # # # ####### # #
# # # # # # # # #
##### # # ####### # # # #######

### ####### ##### ######
# # # # # #
# # # # #
# ##### ##### # #
# # # # #
# # # # # #
### # ##### ######

------------------------------------------
##### ####### # ###### ####### # # ######
# # # # # # # # # # # #
# # # # # # # # # # #
##### # # # ###### # # # ######
# # ####### # # # # # #
# # # # # # # # # # #
##### # # # # # # ##### #

### ####### ##### ######
# # # # # #
# # # # #
# ##### ##### # #
# # # # #
# # # # # #
### # ##### ######

/home/oracle/IFSPtoIFSD/copy1off.unix[130]: sqlplus: not found.
------------------------------------------


*************************************************
Cron: The previous message is the standard output
and standard error of one of your cron commands.

?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top