Re: Input passwords automatically in shell script

From: gazzag <gareth_at_jamms.org>
Date: Thu, 19 Nov 2009 02:38:47 -0800 (PST)
Message-ID: <f70db616-2e6e-474d-82e2-f2ed0bf61db4_at_j14g2000yqm.googlegroups.com>



On 19 Nov, 04:59, Ram <krishna..._at_gmail.com> wrote:
> Hi all,
>
> I have one shell script which is scheduled in cron to restart Oracle
> BI Publisher every day night _at_ 1:00 AM . Even after restarting end
> users complaints that , they don't receive scheduled reports mails .
> So i am plannig to kill all the sessions of that user from cronjob
> itself .
>
> My shell script looks like this
>
> 0 1 * * * /patches/BI_Publisher/restart.sh 2>&1 >> /patches/
> BI_Publisher/restart.log
>
> export ORACLE_HOME=/patches/BI_Publisher/OraHome_1
>
> /patches/BI_Publisher/OraHome_1/jdk/bin/java -jar /patches/
> BI_Publisher/OraHome_1/oc4j_bi/j2ee/home/admin.jar  ormi://localho
> st:23791  oc4jadmin bipub1 -shutdown force
>
> if [ $? -ne 0 ]
> then
> echo " Stop Failed \n "
> else
> echo " Success "
> fi
>
> nohup /patches/BI_Publisher/OraHome_1/oc4j_bi/bin/oc4j -start &
>
> if [ $? -ne 0 ]
> then
> echo " Start Failed \n "
> else
> echo " Success "
> fi
>
> ---------------
> So inorder to achieve i have tried using this command in this shell
> script
>
> ps -ef | grep -i bipub | awk '{ print  $2; }'|grep -v $$|xargs kill -9
>
> But this kills all sessions and now i want  do su to bipub user
> automatically to start the services . To achive this I want to input
> password automaticaly to do su - bipub .
>
> I have tried googling but i am not getting good hits with good
> explanation.
>
> Can any one please help me out.
>
> Regards.

If the cron runs as root, you won't need to supply a password. Simply run the relevant shell-script as follows:

su - bipub -c <shell_script>

HTH -g Received on Thu Nov 19 2009 - 04:38:47 CST

Original text of this message