LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-25-2006, 05:27 AM   #1
comtmr
LQ Newbie
 
Registered: Apr 2006
Location: Ankara \ TURKIYE
Distribution: Red Hat Enterprise 4
Posts: 19

Rep: Reputation: 0
shell script read non-interactive


hi everybody;
I have a rhel4u3 A.S server; oracle db 10g and oracle IAS application server is installed ;
to set enviorement variables ;I have added some lines to .bash_profile of the oracle user ;

[root@orcl ~]# su - oracle
1. Database
2. Application Server

according to the selection enviorement variables and paths are set ;
here is the code ;
1 # .bash_profile
......
15 echo "1. Database"
16 echo "2. Application Server"
17 read ans
18
19 if [ $ans -eq 1 ]; then
20 DISPLAY=:0.0; export DISPLAY
21 ORACLE_BASE=/oracle/db/app/oracle/; export ORACLE_BASE
22 ORACLE_HOME=$ORACLE_BASE/product/10.2.0/; export ORACLE_HOME
23 ORACLE_SID=orcl; export ORACLE_SID
24
......
33 elif [ $ans -eq 2 ]; then
34 ORACLE_BASE=/oracle/ias/app/oracle/; export ORACLE_BASE
35 ORACLE_HOME=$ORACLE_BASE/product/ias; export ORACLE_HOME
.......
43 else
44 echo "WARNING! ORACLE_HOME is not been set"
45 fi
To sum up when the user logs in then ; he enters 1 or 2 to set the variables interactively;

The thing ı want to do is to start the database and application server when server reboots ; so I edited the /etc/oractab file and added the a service named dbora;
as S99dbora and K01dbora to run level 3,5
but when the service tries to start ; the menu appears and wants a selection ; how can I prevent this happening and giving parameter ;

ın fact I thougt to set the variables in the dbora service but then it would be executed as root ; but oracle must be started with oracle user ;
so I used the way seen below ..

#!/bin/sh
....
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl start"
.....

That is all ; tahnks for ant help..
Tamer ONEM
RHCt --- > but will be RHCE
 
Old 09-25-2006, 06:06 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
have you already tried to play around with the $0 variable? i'm not sure but perhaps if you soft-link a script file then execute the soft-link, $0 will be different.

for example
Code:
# cat >scriptfile.sh <<EOF
> #!/bin/bash
> echo $0
> EOF
# ln -s scriptfile.sh db
# ln -s scriptfile.sh ap
# ./scriptfile.sh
scriptfile.sh
# ./db
db
# ./ap
ap
 
Old 09-25-2006, 07:19 AM   #3
comtmr
LQ Newbie
 
Registered: Apr 2006
Location: Ankara \ TURKIYE
Distribution: Red Hat Enterprise 4
Posts: 19

Original Poster
Rep: Reputation: 0
hi dear konsolebox;

hmm I think I could not tell my problem exactly ;
The problem is trying to bypass a read action in a script; without any user activity.. !

But thanks anyway
 
Old 09-25-2006, 07:30 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
what i mean was as continuation to the code... we can have
Code:
if [ "$0" = "db" ]; then
   # do things as if [ $ans -eq 1 ]
elif [ "$0" = "ap" ]; then
   # do things as if [ $ans -eq 2 ]
so on your code you it can be
Code:
if [ $ans -eq 1 ] || [ "$0" = "db" ]; then
   ...
elif [ $ans -eq 2 ] || [ "$0" = "ap" ]; then
   ...
anyway that's all i can tell you. i guess i can't really get what you mean.

regards
 
Old 09-25-2006, 07:52 AM   #5
carl0ski
Member
 
Registered: Sep 2004
Location: Melbourne, Victoria Australia
Distribution: Support those that support you :)
Posts: 872
Blog Entries: 12

Rep: Reputation: 30
Quote:
Originally Posted by konsolebox
what i mean was as continuation to the code... we can have
Code:
if [ "$0" = "db" ]; then
   # do things as if [ $ans -eq 1 ]
elif [ "$0" = "ap" ]; then
   # do things as if [ $ans -eq 2 ]
so on your code you it can be
Code:
if [ $ans -eq 1 ] || [ "$0" = "db" ]; then
   ...
elif [ $ans -eq 2 ] || [ "$0" = "ap" ]; then
   ...
anyway that's all i can tell you. i guess i can't really get what you mean.

regards

Since i'm pretty tired now so deciphering the code is up to you.
but you need the read command

this is from the Suse and Mandriva startup script
Code:
#
# Should we ask for interactive boot mode
#
DO_CONFIRM=""
read -t 2 check < /proc/cmdline 2> /dev/null
case "$check" in
    *confirm*) DO_CONFIRM=yes ;;
esac
test -z "$CONFIRM_PROMPT_TIMEOUT" && CONFIRM_PROMPT_TIMEOUT=5
if test "$PROMPT_FOR_CONFIRM" = "yes" -a "$DO_CONFIRM" != "yes" ; then
    echo -en "${extd}Enter Interactive startup mode?${norm}"
    rc_timer_on "$CONFIRM_PROMPT_TIMEOUT" 37
    read -t "$CONFIRM_PROMPT_TIMEOUT" -n 1 \
	-p " ${extd}y${norm}/[${extd}n${norm}]("${CONFIRM_PROMPT_TIMEOUT}s") " answer
    rc_timer_off
    case "$answer" in
    [yYiI]) DO_CONFIRM=yes ;;
    *)      DO_CONFIRM=    ;;
    esac
    unset answer
    echo
fi
export DO_CONFIRM
 
Old 09-25-2006, 08:51 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
so what should be done here?
 
Old 11-01-2006, 06:54 AM   #7
comtmr
LQ Newbie
 
Registered: Apr 2006
Location: Ankara \ TURKIYE
Distribution: Red Hat Enterprise 4
Posts: 19

Original Poster
Rep: Reputation: 0
two ways to overcome the problem

Hi everyone ;
after a month later I am retruning with 2 valid solutions ;

1.way
I was trying to read an input because of setting enviorement variables for database server (DB) or internet application server (IAS). By setting the env. variables inside the script no read action will be required.
But this solition has an handicap that; the user will not be asked for selection so only db or ias variables will be able to set.

2.way
one of my prof. at univesity used to say that "the first solution you have just found is always the worst one "
Yes the second is setting a time limit for selection then assinging a default value ;

See here ;

#!/bin/bash
ans=33;
read -t 2 ans;
echo $ans;
then the ans would be 33 if user did not enter an input for 2 seconds time.

I don't know if anyone will face this kind of problem but it helped me;
wish this will help others too ;
thanks for all posts.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
read from stdin in a shell script bujecas Linux - General 3 07-03-2009 04:46 PM
[Shell] Read a File from script yussef Programming 4 08-19-2008 04:26 AM
interactive and non-interactive shell linuxjamil Programming 3 09-03-2006 08:42 PM
Serial Port read in shell script tjt Linux - Newbie 1 08-12-2004 09:18 AM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 08:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration