Customize the Shell Script output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Customize the Shell Script output
# 1  
Old 01-29-2015
Customize the Shell Script output

Hello guys.
about two weeks ago i had a question about customizing output and thanks to you guys i could solve it.
now i have a similar question but this time its little complex.
this is my output:
Code:
-------------------+--------------------+---------+---------
ias-component      | process-type       |     pid | status
-------------------+--------------------+---------+---------
DSA                | DSA                |     N/A | Down
LogLoader          | logloaderd         |     N/A | Down
dcm-daemon         | dcm-daemon         |     N/A | Down
OC4J               | home               |   28168 | Alive
OC4J               | home               |   28169 | Alive
OC4J               | home               |   28167 | Down
OC4J               | officeauto         |   12476 | Alive
OC4J               | gaas               |   28170 | Alive
OC4J               | report             |   28172 | Alive
OC4J               | workflow           |    1477 | Alive
OC4J               | messenger          |   28175 | Alive
OC4J               | archive            |   28177 | Alive
OC4J               | GamWS              |   28189 | Alive
OC4J               | sws                |   28108 | Alive
OC4J               | menu               |   28192 | Alive
WebCache           | WebCache           |   27675 | Alive
WebCache           | WebCacheAdmin      |   27671 | Alive
HTTP_Server        | HTTP_Server        |   16552 | Alive

as you can see i have many OC4Js in here and i want to show them like this:
Code:
OK|Home=0 Officeauto=1 . . .

for example if all of the home OC4Js were Alive then HomeValue equals to 1 in other wise Homevalue equals to 0.
i wrote this shell script but it didn't work. i know i should use if but i dont know how!
Code:
HomeValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /home/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
OfficeautoValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /officeauto/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
ReportValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /report/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
WorkflowValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /workflow/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
MessengerValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /messenger/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
ArchiveValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /archive/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
GamWSValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /GamWS/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
SwsValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /sws/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
MenuValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /menu/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
WebCacheValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /WebCache/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
HTTP_ServerValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /HTTP_Server/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')

echo "OK|Home="$HomeValue" Officeauto="$officeautoValue" Report="$reportValue" Workflow="$workflowValue" Messenger="$messengerValue" Archive="$archiveValue" GamWS"$GamWSValue" Sws="$swsValue" WebCache="$WebCacheValue" HTTP_Server="$HTTP_ServerValue""

---------- Post updated at 07:59 AM ---------- Previous update was at 07:47 AM ----------

i forget something:
the OC4Js count is variable. i mean it completely depends to the server configuration.
Thank you.
# 2  
Old 01-29-2015
I can't imagine how the OC4J comes into play. Not sure if you need the upper case initials, either. However, with output being the file name with your results, try
Code:
awk     'NR<=3          {next}
         L[$3]==""      {L[$3]=1}

                        {L[$3]=L[$3] && ($7=="Alive")}

         END            {printf "OK|"
                         for (l in L) printf "%s=%s ", l, L[l]
                         printf "\n"
                        }
        ' output
OK|gaas=1 DSA=0 workflow=1 HTTP_Server=1 home=0 dcm-daemon=0 GamWS=1 officeauto=1 messenger=1 menu=1 archive=1 report=1 sws=1 logloaderd=0 WebCache=1 WebCacheAdmin=1

This User Gave Thanks to RudiC For This Post:
# 3  
Old 01-29-2015
Quote:
Originally Posted by RudiC
I can't imagine how the OC4J comes into play. Not sure if you need the upper case initials, either. However, with output being the file name with your results, try
Code:
awk     'NR<=3          {next}
         L[$3]==""      {L[$3]=1}

                        {L[$3]=L[$3] && ($7=="Alive")}

         END            {printf "OK|"
                         for (l in L) printf "%s=%s ", l, L[l]
                         printf "\n"
                        }
        ' output
OK|gaas=1 DSA=0 workflow=1 HTTP_Server=1 home=0 dcm-daemon=0 GamWS=1 officeauto=1 messenger=1 menu=1 archive=1 report=1 sws=1 logloaderd=0 WebCache=1 WebCacheAdmin=1

Thank you dear RudiC. as always your commands worked perfect.
but i really need to do it with upper cases and in my own format.
so would you please help me to correct my code?
Thank you.
# 4  
Old 01-29-2015
Something like this
Code:
awk     '
        NR<=3          {next}
         L[$3]==""      {L[$3]=1}

                        {L[$3]=L[$3] && ($7=="Alive")}

         END            {printf "OK|"
                           for  (l in L) {
                                str=l
                                str=toupper(substr(str,1,1)) substr(str,2)
                                printf "%s=%s ", str, L[l]
                                }
                         printf "\n"
                        }
        '  output
# print output:
OK|Gaas=1 Menu=1 Sws=1 Report=1 Officeauto=1 Dcm-daemon=0 Archive=1 Workflow=1 Logloaderd=0 DSA=0 Home=0 HTTP_Server=1 WebCacheAdmin=1 GamWS=1 Messenger=1 WebCache=1

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

4. Shell Programming and Scripting

Customize the Shell Script output

Hello guys. i wan to write an script to Customize this output: -------------------+--------------------+---------+--------- ias-component | process-type | pid | status -------------------+--------------------+---------+--------- DSA | DSA | ... (10 Replies)
Discussion started by: Ymir
10 Replies

5. Shell Programming and Scripting

Shell Script output

Hi All, Below is the shell script for which desired output is required: Shell script: #!/bin/bash . /oracle/TEST/db/tech_st/11.1.0/TEST_<hostname>.env sqlplus /nolog << EOF connect / as sysdba spool /home/oracle/db_output.log @lockwait.sql prompt Database Locks ... (1 Reply)
Discussion started by: a1_win
1 Replies

6. UNIX for Advanced & Expert Users

Customize "change password" in unix shell

I want to customize the "change password" through unix shell. when a user's password is expired and he/she logs into shell next time he/she will be asked to change his/her password. At this time when the user provides new password instead of unix doing the "password change" action I want to call my... (4 Replies)
Discussion started by: sharmanikhilesh
4 Replies

7. Shell Programming and Scripting

help me with customize script.

Hi forum members, I have customize command which is opening in one user and while I am try from my user it is not working and getting the message KSH not found. This command is used to open encrypted file ,this command take arguments file name and option ie plz find the below command. ... (1 Reply)
Discussion started by: sivaranga001
1 Replies

8. Shell Programming and Scripting

[How To?] Run shell script and get output into another shell.

Hi guys, I have a simple question, I want to store the output of the following command: As you can see it is running all the time, and we get a new line every 3sec. I just want to store these new lines into a single variable, so I can use it into a script. To clear the screen, and... (4 Replies)
Discussion started by: Thireus
4 Replies

9. Shell Programming and Scripting

How can I customize my login script?

Hi, I am realatively new to UNIX (I started 1 week ago), and I need some help on an assignment. I am trying to find the file that will allow me to modify my login. I did some research, and most of my sources tell me to modify the ~/.cshrc and ~/.login files. The problem is that I cannot find... (1 Reply)
Discussion started by: Hyunkel
1 Replies
Login or Register to Ask a Question