Operating System - HP-UX
1748198 Members
2578 Online
108759 Solutions
New Discussion юеВ

Re: crontab for specific user

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

crontab for specific user

Hi

I need to prepare a crontab on the oracle user. How to write the crontab line and to be sure that user profile will be read before calling the script ?

With AIX i can write something like that:
50 12 * * * /usr/bin/ksh -c "( . /etc/profile; . /gespxpm/ms/users/gespxpm/.profile >/dev/null; . /gespxpm/ms/exp/jcl/ADM_ORA_MajTableSuiviActivite.ksh dba_tools dba >/dev/null 2>&1)"

How to with Hp-UX ?

Regards
Den
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: crontab for specific user

Shalom Den,

I suggest building the profile read into the script.

That seems much easier than what you are doing in AIX.

/usr/bin/su -c username

That format will work in cron.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor
Solution

Re: crontab for specific user

Hi Den:

This would work with HP-UX but you would want to source the user's ".profile" since that is a user's local view whereas '/etc/profile' is the global view.

Having said that, however, there are better ways than sourcing a profile. A profile is designed for interactive use during login. As such, HP-UX '.profile's contain terminal-interactive 'stty' and 'tset' commands that expect the process to be attached to a terminal. A crontask has no controlling terminal and thus sourcing a '.profile' will yield "not a typewriter" messages when 'stty' and/or 'tset' commands execute.

Certainly, you can redirect STDERR to '/dev/null' to eliminate these messages, but that may hide *useful* messages too. One better approach is to only conditionaly execute the 'stty' and 'tset' commands if your environment is associated with a terminal:

if [ -t 0 ]; then
...

A second approach is to put your environmental variables in a file that is separate from your profile. Then, source that file in your profile for logins as well as in crontasks and scripts as needed.

Regards!

...JRF...
Leo The Cat
Regular Advisor

Re: crontab for specific user

Huh

the oracle user crontab below doesn't works.

00,10,20,30,40,50 * * * * /usr/bin/su - oracle /logiciel/app/oracle/oas10g/measures/GenerateOASMeasures.ksh

I finally prefer:

00,10,20,30,40,50 * * * * /usr/bin/ksh -c "( . /etc/profile; . /logiciel/app/oracle/.profile > /dev/null; . /logiciel/app/oracle/oas10g/m
easures/GenerateOASMeasures.ksh >/dev/null 2>&1)"

Regards
Den
James R. Ferguson
Acclaimed Contributor

Re: crontab for specific user

Hi Den:

# su - oracle -c "script"

Regards!

...JRF...
tsf_1
Frequent Advisor

Re: crontab for specific user

Edit and submit a cronfile:
# crontab -e

If cron won't work, try to find error in /var/adm/cron/log. If log has no info, suggest:
(1) check user's incoming mail (system will sent messages if cron failed.
(2) add additioanl entry at cron command to get more hint/error at /tmp/err.txt if cron not working; for example

* * * * * /myscript >> /tmp/err.txt 2>&1
be willing to do, be happy to bear
Leo The Cat
Regular Advisor

Re: crontab for specific user

Thanks it's ok -c and other informations were welcomed.

Regards
Den