Operating System - HP-UX
1832780 Members
3150 Online
110045 Solutions
New Discussion

Re: su - app_user from oracle cronjobs (in a script)

 
SOLVED
Go to solution
Sammy_2
Super Advisor

su - app_user from oracle cronjobs (in a script)


I am running this script from oracle cron.
But within the script I need to su to another user and run that command as that user.How do I do it. See example below.
su - app_user -c command

If i run this command manually from the command line as oracle user, it asks me for a passwd of app_user, which I know but do not know how to put it in a script.
Help neeeded on this please.
good judgement comes from experience and experience comes from bad judgement.
13 REPLIES 13
A. Clay Stephenson
Acclaimed Contributor

Re: su - app_user from oracle cronjobs (in a script)

If you can run your cronjob as user root root then su will not prompt for a password.
If it ain't broke, I can fix that.
Mark Greene_1
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

echo [password]|su - app_user -c command

HTH
mark
the future will be a lot like now, only later
Mladen Despic
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

Let host=`hostname` and user=`whoami`.
If $user is not root, then
you can try this:

1. Edit ~app_user/.rhosts so it includes:

$host $user

2. As $user, run:

remsh $host -l app_user -n "command"
Kevin Wright
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

Put it in roots crontab.
MANOJ SRIVASTAVA
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

Hi SAM

run as a cron for root and then su to oracle or the user it wont ask for passwd.

Here is what I do to with my crons :


echo " merge started " | sendmail 5712157544@mobile.att.net
su - oracle -c "/home/oracle/report_bkup/ShutDB PBSCS" > /tmp/mergelog
su - oracle -c "/home/oracle/report_bkup/ShutDB PRTX" >> /tmp/mergelog
/usr/local/adm/bcv/umount_bcv.ksh bcvgrp1 M3 >> /tmp/mergelog
/usr/local/adm/bcv/umount_bcv.ksh bcvgrp2 M3 >> /tmp/mergelog
/usr/local/adm/bcv/merge_bcv.ksh bcvgrp1 M3 >> /tmp/mergelog
/usr/local/adm/bcv/merge_bcv.ksh bcvgrp2 M3 >> /tmp/mergelog
echo " merge completed " | sendmail 5712157544@mobile.att.net

/usr/local/adm/bcv/cond

exit


Manoj Srivastava

Deshpande Prashant
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

HI
If possible, run the script/command under application user's cronjob.

Prashant.
Take it as it comes.
Sammy_2
Super Advisor

Re: su - app_user from oracle cronjobs (in a script)

Thanks for the responses. But I do not have access to root cron. I just have access to oracle and app_user cron and passwords. And so
I can't run it as root crontab. Is using root cron (and then su' ing to another user) only way to do it ?

The below command does not work as it still
prompts for a passwd.
=====================
$ id
uid=101(oracle) gid=101(dba) groups=102(www)
$ echo "password" | su - app_user -c halt_cmd
Password:
su: Sorry
==================
good judgement comes from experience and experience comes from bad judgement.
Mark Greene_1
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

yes, my apologies but piping the password through standard-in will not work. if you give the cron info to the admins who do have root access, it ought not to be a big deal for them to add it to root's crontab for you.

mark
the future will be a lot like now, only later
Mladen Despic
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

Have you tried using remsh instead? See my previous post.
Jean-Luc Oudart
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

You can write a small C program that will call your script. compile as the target user and change set user bit on the exe.
You should have the relevant permissions.

You can restrict execution with ACLs if you wish to do so.
fiat lux
Sanjay_6
Honored Contributor

Re: su - app_user from oracle cronjobs (in a script)

Hi Sam,

You can try expect to supply the password for the user id. You may have to look into more detail in this link to see if this suits your purpose,

http://expect.nist.gov/

Hope this helps.

Regds
Sanjay_6
Honored Contributor
Solution

Re: su - app_user from oracle cronjobs (in a script)

Hi Sam,

Here is another link to download expect,

http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.33/

Hope this helps.

Regds
Sammy_2
Super Advisor

Re: su - app_user from oracle cronjobs (in a script)

Thanks everyone. I will just use root cron and su - app_user as suggested by most of you. Better than writing a c program and do remsh.
good judgement comes from experience and experience comes from bad judgement.