Sponsored Content
Top Forums Shell Programming and Scripting Facing problem with Alias created through script. Post 302959293 by venky.b5 on Saturday 31st of October 2015 06:22:50 AM
Old 10-31-2015
Facing problem with Alias created through script.

Hi Guru's,

I am creating alias for db instance running on a server through script, am able to create them based on /etc/oratab entries and can use successfully with the below script.

Code:
#!/bin/bash

SCRIPT_PATH=${HOME}/scripts/db/script
LOG_FILE=${HOME}/scripts/db/log/database_instances_alias.log
CONN_DATABASE='sqlplus -s / as sysdba'
DB_INSTANCES=$(cat /etc/oratab | egrep -v '^#|^$' | grep -v '^+'|cut -d":" -f1,2)
sed -n '1,8p' ${HOME}/.bashrc > ${HOME}/.bashrc_bkp
echo " " >>${HOME}/.bashrc_bkp
printf "%s%20s%20s%20s%20s\n" "S.No" "DATABASENAME"  "ORACLE_HOME"  "DB_STATUS" "DB_MODE" > ${LOG_FILE}
SERIAL=0
for SINGLE_INSTANCE in ${DB_INSTANCES[@]}
do
##DATABASE NAMES
DATABASE_NAME=$(echo $SINGLE_INSTANCE | awk -F ":" '{print $1}')
##ORACLE HOME
DATABASE_HOME=$(echo $SINGLE_INSTANCE | awk -F ":" '{print $2}')
ps -ef | grep pmon | grep -q $DATABASE_NAME
  if [ $? -eq 0 ]; then
    DB_STATUS="UP"
    export ORACLE_SID=$DATABASE_NAME
    export ORACLE_HOME=$DATABASE_HOME
    DATABASE_MODE=$(echo "select open_mode from v\$database;" | $CONN_DATABASE | sed -n '4p')
       case $DATABASE_MODE in
             'MOUNT')
                                DATABASE_MODE_S=${DATABASE_MODE}
             ;;
             'READ WRITE')
                                DATABASE_MODE_S=${DATABASE_MODE}
             ;;
             'READ ONLY')
                                DATABASE_MODE_S=${DATABASE_MODE}
             ;;
             'NOMOUNT')
                                DATABASE_MODE_S='Instance Running Not Mounted'
             ;;
             *)
                                DATABASE_MODE_S='N/A'
             ;;
       esac

  else
    DB_STATUS="DOWN"
    DATABASE_MODE_S="N/A"
  fi
SERIAL=$(expr $SERIAL + 1)
printf "%s%20s%25s%15s%20s\n" "$SERIAL" "$DATABASE_NAME"  "$DATABASE_HOME"  "$DB_STATUS" "$DATABASE_MODE_S" >> ${LOG_FILE}
echo "alias $SERIAL='export ORACLE_SID="$DATABASE_NAME";export ORACLE_HOME="$DATABASE_HOME";PS1=\"[\\u\\h ] $DATABASE_NAME \$\"'" >> ${HOME}/.bashrc_bkp
echo "alias showdb='$SCRIPT_PATH/database_instances_alias_bkp.sh;cat $LOG_FILE;. $HOME/.bashrc'" >>${HOME}/.bashrc_bkp
done
mv -f $HOME/.bashrc_bkp $HOME/.bashrc
. $HOME/.bashrc

But i am facing problem when the number of entries changed
like
suppose there are 8 entries in oratab and the script will create 8 aliasis, if i delete 2 entries from oratab so script will create alias for 6 entries only, but am not able to unalias 7 and 8. so how can i unalias them

someone please help

Regard's
Venkat
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

facing a problem in redirection

Hi, I am doing this perl script print (@line(1..15)); the lines 1 to 15 get printed... how can i redirect this to file? thanks and regards vivek.s (4 Replies)
Discussion started by: vivekshankar
4 Replies

2. Solaris

please help as i am facing problem with uptime

Hi I am getting the uptime output as follows 12:40am up 4 day(s), 18:29, 2 users, load average: 38.97, 36.54, 34.89 The load average is too high . I have checked the processes , but no process is taking too much cpu time Please help (3 Replies)
Discussion started by: guy009
3 Replies

3. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

4. Solaris

Facing problem with zone

i am using this way to create zone1 and zone2 bash-2.05b# zonecfg -z zone1 zone1: No such zone configured Use 'create' to begin configuring a new zone. zonecfg:zone1> create zonecfg:zone1> set zonepath=/zone/1 zonecfg:zone1> set autoboot=true zonecfg:zone1> add net zonecfg:zone1:net>... (6 Replies)
Discussion started by: coxmanchester
6 Replies

5. Shell Programming and Scripting

problem facing in if -else condition

can u plz tell me where is the error echo enter the filename to be searched read fname if #-d $fname then echo file exists if then echo itsa directory elif then echo its readable cat $fname else echo its not readable fi else ... (1 Reply)
Discussion started by: gotam
1 Replies

6. Solaris

Facing Problem with metaset in SVM

hi all, i am using solaris 5.10 on sun blade 150 and i am trying to configure diskset in sun volume manager. When i fire the following command, it says some rpc related error. bash-3.00# metaset -s kingston -a -h u15_9 metaset: u15_9: metad client create: RPC: Program not registered how to... (4 Replies)
Discussion started by: kingston
4 Replies

7. Shell Programming and Scripting

created a .alias, but they won't take (ksh)

I login with a common username, and have no access to the different login scripts for my personalizations. So for a while, I would hobble on over to a directory I made for myself, and then bring in my alias file where I would fix my backspace, create a few aliases, etc.: $ ./.alias $ Now... (4 Replies)
Discussion started by: hindesite
4 Replies

8. AIX

facing problem using su

Hi, I am able to login using su - or su directly , # prompt is coming, it doesnt ask for password. any normal user on aix system is login using su - or su . Please suggest where to change the configuration direct root login is disabled in /etc/ssh/sshd_config file. (0 Replies)
Discussion started by: manoj.solaris
0 Replies

9. Shell Programming and Scripting

Facing problem in the sqlldr & shell script

Guys i am facing two problems : (1) when i create the sql loader file the date format i m getting is this 28-DEC-11 12.03.14.107137 AM; for this i m using this script but unable to load the files trailing nullcols ( SERIALNO, AMOUNT, CLASS, MDN, VDATE "to_date(:TIMESTAMP, 'DD-MON-YY... (6 Replies)
Discussion started by: xal_kaushi
6 Replies
WHICH(1)						      General Commands Manual							  WHICH(1)

NAME
which - shows the full path of (shell) commands. SYNOPSIS
which [options] [--] programname [...] DESCRIPTION
Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been exe- cuted when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash(1). This man page is generated from the file which.texinfo. OPTIONS
--all, -a Print all matching executables in PATH, not just the first. --read-alias, -i Read aliases from stdin, reporting matching ones on stdout. This is useful in combination with using an alias for which itself. For example alias which='alias | which -i'. --skip-alias Ignore option `--read-alias', if any. This is useful to explicity search for normal binaries, while using the `--read-alias' option in an alias or function for which. --read-functions Read shell function definitions from stdin, reporting matching ones on stdout. This is useful in combination with using a shell func- tion for which itself. For example: which() { declare -f | which --read-functions $@ } export -f which --skip-functions Ignore option `--read-functions', if any. This is useful to explicity search for normal binaries, while using the `--read-functions' option in an alias or function for which. --skip-dot Skip directories in PATH that start with a dot. --skip-tilde Skip directories in PATH that start with a tilde and executables which reside in the HOME directory. --show-dot If a directory in PATH starts with a dot and a matching executable was found for that path, then print "./programname" rather than the full path. --show-tilde Output a tilde when a directory matches the HOME directory. This option is ignored when which is invoked as root. --tty-only Stop processing options on the right if not on tty. --version,-v,-V Print version information on standard output then exit successfully. --help Print usage information on standard output then exit successfully. RETURN VALUE
Which returns the number of failed arguments, or -1 when no `programname' was given. EXAMPLE
The recommended way to use this utility is by adding an alias (C shell) or shell function (Bourne shell) for which like the following: [ba]sh: which () { (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@ } export -f which [t]csh: alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' This will print the readable ~/ and ./ when starting which from your prompt, while still printing the full path when used from a script: > which q2 ~/bin/q2 > echo `which q2` /home/carlo/bin/q2 BUGS
The HOME directory is determined by looking for the HOME environment variable, which aborts when this variable doesn't exist. Which will consider two equivalent directories to be different when one of them contains a path with a symbolic link. AUTHOR
Carlo Wood <carlo@gnu.org> SEE ALSO
bash(1) WHICH(1)
All times are GMT -4. The time now is 11:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy