Customize the Shell Script output


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

Hello guys.
i wan to write an script to Customize this output:

Code:
-------------------+--------------------+---------+---------
ias-component      | process-type       |     pid | status
-------------------+--------------------+---------+---------
DSA                | DSA                |     N/A | Down
LogLoader          | logloaderd         |     N/A | Down
dcm-daemon         | dcm-daemon         |    3948 | Alive
OC4J               | home               |    4207 | Alive
OC4J               | officeauto         |    3955 | Alive
OC4J               | gaas               |    4208 | Alive
OC4J               | report             |    3957 | Alive
OC4J               | workflow           |    3953 | Alive
OC4J               | messenger          |    3950 | Alive
OC4J               | archive            |    3956 | Alive
OC4J               | GamWS              |    3958 | Alive
OC4J               | menu               |    3949 | Alive
OC4J               | sws                |    3952 | Alive
WebCache           | WebCache           |    4070 | Alive
WebCache           | WebCacheAdmin      |    4209 | Alive
HTTP_Server        | HTTP_Server        |    3951 | Alive

to something like this:
Code:
Home=1(if its Alive and 0 if its down)
officeauto=1
.
.
.

I'mnew in Linux scripting and really appropriate any sort of help.
thank you gays.

Last edited by Don Cragun; 01-24-2015 at 05:59 AM.. Reason: Add CODE tags.
# 2  
Old 01-24-2015
I'm not at all sure that I understand what you're trying to do.

You say you want to print Home=1 (if it is Alive) or Home=2 (if it is down, but down with a lowercase d does not appear anywhere in your input), but instead of printing DSA=2, you printed nothing??? You say the first line of the output should be Home=1, but Home (with an uppercase H) does not appear anywhere in your input data???

Please give a clearer description of what output you hope to produce from this output. Please tell us what form this output takes. (Is it a string in a shell variable? Is it being written to a pipe by some other process? Is it stored in a file?) Please tell us what you want to do with the transformed output.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 01-24-2015
No attempts nor ideas from your side?
However, try
Code:
awk -F\| 'NR>3{gsub (/ /,_); print $2 "=" ($4=="Alive")}' file
DSA=0
logloaderd=0
dcm-daemon=1
home=1
officeauto=1
gaas=1
report=1
workflow=1
messenger=1
archive=1
GamWS=1
menu=1
sws=1
WebCache=1
WebCacheAdmin=1
HTTP_Server=1

This User Gave Thanks to RudiC For This Post:
# 4  
Old 01-24-2015
Or:
Code:
awk -F' *[|] *' '$4=="Down"{print $2 "=" 0} $4=="Alive"{print $2 "=" 1}' file

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 01-24-2015
Thank you so much dear Don, Rudic and Scurit.
let me explain my problem again:
i want to execute this command and then customize the output.
Code:
output=$(su - oracle -c'/oracleAS10g/product/opmn/bin/opmnctl status')

the output is the same one i posted in my first thread.
i guess awk need a file but i just want to analyze the command output.

thank you.

Last edited by Scrutinizer; 01-24-2015 at 09:36 AM.. Reason: code tags
# 6  
Old 01-24-2015
Please use code tags as required by forum rules!

Please make yourself familiar with "redirection" and "pipes" in *nix, e.g. man sh/bash/ksh.
Try
Code:
su - oracle -c'/oracleAS10g/product/opmn/bin/opmnctl status' | awk -F\| 'NR>3{gsub (/ /,_); print $2 "=" ($4=="Alive")}'

This User Gave Thanks to RudiC For This Post:
# 7  
Old 01-24-2015
Quote:
Originally Posted by RudiC
Please use code tags as required by forum rules!

Please make yourself familiar with "redirection" and "pipes" in *nix, e.g. man sh/bash/ksh.
Try
Code:
su - oracle -c'/oracleAS10g/product/opmn/bin/opmnctl status' | awk -F\| 'NR>3{gsub (/ /,_); print $2 "=" ($4=="Alive")}'

Thank you dear RudiC.
would you lease explain little bit your code?
the output has a little problem but it worked.
i want to try split the command and fix the problem. i use this one but it didnt work:
Code:
output=$(su - oracle -c'/oracleAS10g/product/opmn/bin/opmnctl status')
echo $output | awk -F\| 'NR>3{gsub (/ /,_); print $2 "=" ($4=="Alive")}'

the command output is:
Code:
=0
process-type=0
=0
DSA=0
logloaderd=0
dcm-daemon=1
home=1
officeauto=1
gaas=1
report=1
workflow=1
messenger=1
archive=1
GamWS=1
menu=1
sws=1
WebCache=1
WebCacheAdmin=1
HTTP_Server=1
=0

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. 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: -------------------+--------------------+---------+--------- ias-component | process-type ... (3 Replies)
Discussion started by: Ymir
3 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