LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2012, 04:27 PM   #1
kais1
Member
 
Registered: Dec 2008
Posts: 61

Rep: Reputation: 17
Shell script


Dear all,

I have the below commands in a shell script..


Code:


######################################################################
#                                                                    #
#                                                                    #
#               ORACLE RAC STATUS                                    #
#                                                                    #
#                                                                    #
######################################################################

echo  "CHECK CLUSTER COMPONENT STATUS"
######################################
/s01/oracle/prodcrs/10.2.0/bin/crs_stat -t


echo  "CHECK NODEAPPS STATUS OF MEDDB1"
#######################################
srvctl status nodeapps -n MEDDB1


echo  "CHECK NODEAPPS STATUS OF MEDDB2"
#########################################
srvctl status nodeapps -n MEDDB2
when am running the script, the output is continous with out any break as you can see below


Code:
CHECK NODEAPPS STATUS OF MEDDB1
VIP is running on node: MEDDB1
GSD is running on node: MEDDB1
Listener is running on node: MEDDB1
ONS daemon is running on node: MEDDB1
CHECK NODEAPPS STATUS OF MEDDB2
VIP is running on node: MEDDB2
GSD is running on node: MEDDB2
Listener is running on node: MEDDB2
ONS daemon is running on node: MEDDB2
I need to have a gap between the lines and to print ORACLE RAC Status in the box (as it is ) to the output file . Please guide

Kai

Last edited by colucix; 03-17-2012 at 04:49 PM. Reason: Adjusted CODE tags
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-17-2012, 04:41 PM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,252

Rep: Reputation: 313Reputation: 313Reputation: 313Reputation: 313
To achieve empty line (a gap) you can write just "echo":
Code:
echo
And to get "ORACLE RAC Status in the box" use echo in front and quote text. For example:
Code:
echo '# ORACLE RAC STATUS #'
P.S. Your CODE tag is not working, maybe it should be written in capitalized characters.

Last edited by eSelix; 03-17-2012 at 04:44 PM.
 
1 members found this post helpful.
Old 03-17-2012, 04:51 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by eSelix View Post
P.S. Your CODE tag is not working, maybe it should be written in capitalized characters.
Tags are case-insensitive. The OP wrote [code][code] instead of [code][/code]. Fixed.
 
1 members found this post helpful.
Old 03-17-2012, 04:53 PM   #4
kais1
Member
 
Registered: Dec 2008
Posts: 61

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by eSelix View Post
To achieve empty line (a gap) you can write just "echo":
Code:
echo
And to get "ORACLE RAC Status in the box" use echo in front and quote text. For example:
Code:
echo '# ORACLE RAC STATUS #'
P.S. Your CODE tag is not working, maybe it should be written in capitalized characters.
Thanks , that helps. one small info required.. that I need the caption to be in the centre of the line, I tried the below, but doesn't work

Code:
                    echo '# ORACLE RAC STATUS #'
but the above is still in the starting of the line ..

Kai

Last edited by colucix; 03-17-2012 at 05:10 PM. Reason: CODE tags fixed
 
Old 03-17-2012, 05:02 PM   #5
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,252

Rep: Reputation: 313Reputation: 313Reputation: 313Reputation: 313
You can use additional space characters after first # to move text away. But how to really and profesionally center text in console with Bash (taking into account maximum width of output) I don't known, maybe others. I think this is not possible without additional function and maybe not neccessary for your purposes.
 
1 members found this post helpful.
Old 03-17-2012, 05:54 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
To print out the ORACLE RAC STRING as written in your example, just add echo at the beginning of the lines and quote the text, e.g.
Code:
echo '######################################################################'
echo '#                                                                    #'
echo '#                                                                    #'
echo '#                          ORACLE RAC STATUS                         #'
echo '#                                                                    #'
echo '#                                                                    #'
echo '######################################################################'
Since it has to be written to a file, you must manually center the string.

Generally speaking - if you want to center a string in a terminal - you need to retrieve the width of the current terminal and do some computation to center the text using the printf command. Example:
Code:
#!/bin/bash
COLUMNS=$(tput cols)
string='ORACLE RAC STATUS'
printf -v rep "%${COLUMNS}s" && echo ${rep// /#}
printf "#%$((($COLUMNS)-1))s\n" "#"
printf "#%$((($COLUMNS)-1))s\n" "#"
printf "#%$(((${#string}+$COLUMNS)/2))s%$((($COLUMNS-${#string}-1)/2))s\n" "$string" "#"
printf "#%$((($COLUMNS)-1))s\n" "#"
printf "#%$((($COLUMNS)-1))s\n" "#"
printf -v rep "%${COLUMNS}s" && echo ${rep// /#}
Please notice that COLUMNS is an environment variable bound to the terminal and it is not set inside a script. For this reason I used the tput command to retrieve the width of the terminal and assigned the value to the COLUMNS variable.

Last edited by colucix; 03-17-2012 at 05:55 PM.
 
2 members found this post helpful.
Old 03-18-2012, 12:49 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Could also try a here document:
Code:
cat <<END
######################################################################
#                                                                    #
#                                                                    #
#               ORACLE RAC STATUS                                    #
#                                                                    #
#                                                                    #
######################################################################
END
 
1 members found this post helpful.
Old 03-18-2012, 08:01 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Personally I'd consider the bash printf cmd http://wiki.bash-hackers.org/commands/builtin/printf, much like the one in C or Perl etc...
 
1 members found this post helpful.
Old 03-23-2012, 03:02 PM   #9
kais1
Member
 
Registered: Dec 2008
Posts: 61

Original Poster
Rep: Reputation: 17
Thanks to all .

Kai
 
Old 03-23-2012, 05:51 PM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
To clarify some of the previous posts, in bash, # is a comment. Any line that begins with # is a comment line, which means it has no effect on the program, output, anything, it's just to allow you to comment the program so you can understand what is going on when you go back and read it later. If you actually want the script to print out a literal "#", then put an "echo" in front of it and quote it with single quotes, as the previous posters described.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 10:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 08:58 PM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 02:45 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM


All times are GMT -5. The time now is 01:09 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration