LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   shell script read non-interactive (https://www.linuxquestions.org/questions/linux-general-1/shell-script-read-non-interactive-486749/)

comtmr 09-25-2006 05:27 AM

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 :)

konsolebox 09-25-2006 06:06 AM

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


comtmr 09-25-2006 07:19 AM

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 :)

konsolebox 09-25-2006 07:30 AM

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

carl0ski 09-25-2006 07:52 AM

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


konsolebox 09-25-2006 08:51 AM

so what should be done here?

comtmr 11-01-2006 06:54 AM

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.


All times are GMT -5. The time now is 06:25 AM.