LinuxQuestions.org
Help answer threads with 0 replies.
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 03-14-2019, 09:46 AM   #1
Alok Behria
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Rep: Reputation: Disabled
Shell Scripting ..


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.

#!/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

Regards
 
Old 03-14-2019, 10:17 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,512
Blog Entries: 13

Rep: Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029
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.
 
1 members found this post helpful.
Old 03-14-2019, 10:19 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,158

Rep: Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386Reputation: 5386
Quote:
Originally Posted by Alok Behria View Post
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.
 
2 members found this post helpful.
Old 03-14-2019, 06:08 PM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 2,741

Rep: Reputation: 708Reputation: 708Reputation: 708Reputation: 708Reputation: 708Reputation: 708Reputation: 708
Quote:
Originally Posted by rtmistler View Post
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.
 
1 members found this post helpful.
Old Yesterday, 05:53 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,293

Rep: Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801Reputation: 3801
the simple way is to try:
Code:
cat /etc/oratab|grep -v "^#"|grep -v "N$"|cut -f1 -d: -s # with and/or without -s
cat /etc/oratab|grep -v "^#"|cut -f1 -d: -s              # with and/or without -s
# anything else you want
but obviously you can read man cut to check -s. and man grep
 
1 members found this post helpful.
Old Yesterday, 08:20 AM   #6
tyler2016
Member
 
Registered: Sep 2018
Distribution: Debian, CentOS, FreeBSD
Posts: 58

Rep: Reputation: Disabled
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
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 08:03 AM
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-12-2013 11:20 PM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM

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

All times are GMT -5. The time now is 11:56 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration