Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have got the following code , which uses shell script to log on various database's running on server by setting up the database environment by getting the database SID in variable and passing this value further to set up the database SID and binary location.
Here on step 1 , I have got 1 confusion and not really sure what these commands does here.
#!/bin/ksh
ALL_DATABASES=`cat /etc/oratab|grep -v "^#"|grep -v "N$"|cut -f1 -d: -s` ## what does N$ and -s flag will do here and
for DB in $ALL_DATABASES
do
unset TWO_TASK
export ORACLE_SID=$DB
export ORACLE_HOME=`grep "^${DB}:" /etc/oratab|cut -d: -f2 -s`
export PATH=$ORACLE_HOME/bin:$PATH
echo "---> Database $ORACLE_SID, using home $ORACLE_HOME"
sqlplus -s "/as sysdba" <<-EOF
select * from global_name;
exit;
EOF
done
Please use [code] tags when posting code. It helps the readability.
N$ is purely a string that the grep is searching for.
The -s flag is part of the cut command. Please check the manual page for cut, which explains that it will not print lines that do not contain a delimiter. Note: The -d flag defines what said delimiter is to be.
Hi All,
I have got the following code , which uses shell script to log on various database's running on server by setting up the database environment by getting the database SID in variable and passing this value further to set up the database SID and binary location. Here on step 1 , I have got 1 confusion and not really sure what these commands does here.
Code:
#!/bin/ksh
ALL_DATABASES=`cat /etc/oratab|grep -v "^#"|grep -v "N$"|cut -f1 -d: -s` ## what does N$ and -s flag will do here and
for DB in $ALL_DATABASES
do
unset TWO_TASK
export ORACLE_SID=$DB
export ORACLE_HOME=`grep "^${DB}:" /etc/oratab|cut -d: -f2 -s`
export PATH=$ORACLE_HOME/bin:$PATH
echo "---> Database $ORACLE_SID, using home $ORACLE_HOME"
sqlplus -s "/as sysdba" <<-EOF
select * from global_name;
exit;
EOF
done
You have been asking about shell scripts for SEVEN YEARS now; you also need to read the "Question Guidelines" link in my posting signature. We are happy to help you, but you have to show effort of your own and do basic research. Have you actually tried to look at the command? Read the man pages for the various pieces, and the options that they use? Or even just tried to run that command-chain in a terminal, and change things to see the results??
If you want to know what it does, then you need to read the man pages for the grep and cut commands.
Please use [code] tags when posting code. It helps the readability.
N$ is purely a string that the grep is searching for.
The -s flag is part of the cut command. Please check the manual page for cut, which explains that it will not print lines that do not contain a delimiter. Note: The -d flag defines what said delimiter is to be.
Also, the cat /etc/oratab is unnecessary and is known as “cat abuse”. Add /etc/oratab to the grep command.
grep -v "N$" will give you all lines that do NOT end in N. $ in regular expressions means the end of the line. I think (could be wrong) in /etc/oratab a line that ends in N means that SID set to not start at boot.
From the cut man page:
Code:
-s, --only-delimited
do not print lines not containing delimiters
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.