LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 04-10-2009, 02:49 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129

Rep: Reputation: 17
Glassfish - Obtain Name & PID and format output


I want to get the pid for each domain, nodeagent and application running in glassfish. I then need to format that data to enable ease of reading. Here is what I have thus far for the domain only but it does not work. I can get the PID to display but I need it formatted.

Code:
#!/bin/bash

sudo find /opt/SUN/SUNAppSrv -name .__com* | grep domain > /tmp/pid_domain

#echo $1
List="$(cat /tmp/pid_domain)"
echo 'List' "$List"
for strng in "$List";
do
echo 'in the loop'
awk -F '/' '{ print $7 }' $strng
cat $strng > pid
BEGIN { FS= "/" #make tab the field separator
printf("%15s %5s",
"Name" , "PID")
}
{ printf("%15s %6d", $1 $pid
}
END { printf("\n%15s %6d") }
done
echo 'COMPLETED'

Want output to look like:
Name PID

DomainName pid

Here is what I get:
List /opt/SUN/SUNAppSrv/9.1.01/domains/PCTestDomain/config/.__com_sun_appserv_pid
./pidglean.sh: line 16: syntax error near unexpected token `"%15s %5s",'
./pidglean.sh: line 16: ` printf("%15s %5s",'

I know this is pretty site specific. Any help with the code would be great. I'm just really unfamiliar with awk but wanting to learn more about it. Thank you.
 
Old 04-10-2009, 03:02 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The printf statement in awk does not requires parentheses. A correct form is
Code:
printf "%15s %5s","Name","PID"
Moreover you're not executing the printf statement in awk. You should do something like:
Code:
awk '
<awk statements here>
' filename
that is you can include an awk program inside a shell script, but you have to take care of the correct syntax, using single quotes to enclose the whole awk program. Anyway, you are using awk just to do a formatted printing, but the same task can be accomplished by the printf statement in bash, without the need for awk code.
 
  


Reply



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
how to format the output? Carlos2dub Programming 3 02-17-2009 10:09 AM
Format output pslacerda Linux - Newbie 12 12-21-2008 09:01 AM
Something like xkill, but just output the PID or resource ID, don't kill musther Linux - Software 2 10-29-2007 10:28 PM
obtain pid of a kernel thread ratwings Linux - Software 0 02-11-2005 03:54 PM
iptables OUTPUT rules: DROP by process (PID)? gregory76 Linux - Security 6 07-11-2003 04:28 PM

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

All times are GMT -5. The time now is 07:07 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
Open Source Consulting | Domain Registration