LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Glassfish - Obtain Name & PID and format output (https://www.linuxquestions.org/questions/linux-general-1/glassfish-obtain-name-and-pid-and-format-output-718288/)

j-me 04-10-2009 02:49 PM

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.

colucix 04-10-2009 03:02 PM

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.


All times are GMT -5. The time now is 03:25 AM.