Script to list applications in alphabetical order


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to list applications in alphabetical order
# 1  
Old 09-21-2012
Script to list applications in alphabetical order

I've looking over a script for work and I've had a problem with the script not listing the files in alphabetical order. To look up PIDs for apps, it would be beneficial to have them listed in that order. Here is what I've been reviewing.

Code:
#!/usr/bin/perl

$str = sprintf "%4s %-40s", "PID", "SERVER NAME";
print "$str\n";

{
 @tomcat_ps = `/usr/ucb/ps auxwwe |grep -v grep| grep -i CATALINA_BASE`;

  foreach $line (@tomcat_ps)
  {
  $_ = $line;
  /.*weblogic (.*[0-9]) \ [0-9].[0-9] .*Dcatalina.base=(\/.*) .*Dcatalina.home*/;
  print "$1 $2\n";
  }
}

I know inserting the sort feature would allow this but i'm not sure where to put it. Trial and error has gotten me no results. Any help would be appreciated.

-Thanks!

Last edited by Corona688; 09-21-2012 at 04:05 PM..
# 2  
Old 09-21-2012
If you find yourself doing lots of system(), backticks, and lists-of-lines in Perl, it's probably best redone in shell. I learned Perl first and learned to regret it, when I realized my scripts were 99% shell with a thin topping of perl and were cut in half by leaving out the Perl.

That can probably be handled in one shell and one or two external commands, rather than perl and a shell(every time you use system or backticks, you're running a new shell and four external commands if you'll explain what you're trying to do rather than the way you want to do it.

What are you actually trying to do here? What output do you get from /usr/ucb/ps auxwwe, and what output do you want from your script?
# 3  
Old 09-21-2012
I would like to execute the script and have the following print out:
PID SERVER NAME
27563 /www/aapple
27435 /www/apple
28432 /www/orange
3432 /www/peach

I need a sort on the last file path independent of the PID.
# 4  
Old 09-21-2012
Your output doesn't resemble anything your program would produce even unsorted, not containing CATALINA_BASE anywhere for example.

I need the input too, which is why I asked for it too.
Quote:
Originally Posted by Corona688
What output do you get from /usr/ucb/ps auxwwe
Since you're using /usr/ucb/ps I can assume you're using Solaris, which is good to know because it changes your options a lot.
# 5  
Old 09-21-2012
Sorry, I didn't read all the way through.

Running /usr/ucb/ps auxwwe prints all the PIDS for all the apps. There are about 100 or so apps and the output is massive, excessive and unnecessary.

There are multple PIDS per app and I only need the base for all the apps which is what the following prints out: /usr/ucb/ps auxwwe |grep -v grep| grep -i CATALINA_BASE
# 6  
Old 09-21-2012
Quote:
Originally Posted by whysolucky
Running /usr/ucb/ps auxwwe prints all the PIDS for all the apps. There are about 100 or so apps and the output is massive, excessive and unnecessary.
Obviously I don't need to see all 100 lines. I do need to see what it looks like.

Telling me its a 'list of processes' is a no-brainer, that's what ps is for. Which columns to grab is less obvious. My ps probably doesn't look anything like yours.

Please do not leave people guessing. Show a representative sample of input, desired output, attempts at a solution and specify what OS and versions being used, or this thread will be closed.
# 7  
Old 09-21-2012
SunOS hgsun50 5.10 Generic_142900-09 sun4v sparc SUNW,Sun-Fire-T200

Code:
USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND
root     27503  0.0  0.0 5704 3800 ?        S 13:27:05  0:00 /usr/lib/ssh/sshd
weblogic 27504  0.0  0.0 9872 6176 ?        S 13:27:05  0:00 /usr/lib/ssh/sshd
weblogic 27511  0.0  0.0 3528 2624 pts/27   S 13:27:10  0:00 -bash USER=weblogic LOGNAME=weblogic HOME=/export/home/weblogic PATH=/usr/bin MAIL=/var/mail//weblogic SHELL=/usr/bin/bash TZ=US/Eastern LC_CTYPE=en_US.ISO8859-1 LC_COLLATE=en_US.ISO8859-1 LC_TIME=en_US.ISO8859-1 LC_NUMERIC=en_US.ISO8859-1 LC_MONETARY=en_US.ISO8859-1 LC_MESSAGES=C SSH_CLIENT=10.8.84.67 64761 22 SSH_CONNECTION=10.8.84.67 64761 192.168.173.50 22 SSH_TTY=/dev/pts/27 TERM=xterm
weblogic 28783  0.0  0.0 1856  176 ?        S   Jul 26  0:00 /bin/sh /www/staging/bea/domains/mydomain4/bin/startWebLogic_managed_custom_itms.sh nodebug nopointbase noiterativedev notestconsole ADMIN_URL=http://hgsun50:6001 EDITOR=vi HOME=/export/home/weblogic JAVA_HOME=/www/staging/bea/jdk160_21 LC_COLLATE=en_US.ISO8859-1 LC_CTYPE=en_US.ISO8859-1 LC_MESSAGES=C LC_MONETARY=en_US.ISO8859-1 LC_NUMERIC=en_US.ISO8859-1 LC_TIME=en_US.ISO8859-1 LOGNAME=weblogic MAIL=/var/mail//weblogic PATH=/www/staging/bea/jdk160_21/bin:/bin:/usr/bin:/usr/ucb:/usr/local/bin:/www/staging/bea/modules/org.apache.ant_1.6.5/bin:/www/staging/builds/sos/bin:/sbin:/usr/sbin:/usr/bin PWD=/www/staging/bea/domains/mydomain4/bin SERVER_NAME=server310 SHELL=/usr/bin/bash SHLVL=2 SSH_CLIENT=10.8.84.67 49347 22 SSH_CONNECTION=10.8.84.67 49347 192.168.173.50 22 SSH_TTY=/dev/pts/15 SUPPORT_LIBS=/www/staging/lib/ TERM=vt100 TZ=US/Eastern USER=weblogic WEBJOBS_BIN=/www/staging/webjobs/bin WEBJOBS_CONFIG=/www/staging/webjobs/bin/config WEBJOBS_HOME=/www/staging/webjobs WEBJOBS_LOGS=/www/staging/webjobs/bin/logs WLS_PW= WLS_USER= WL_HOME=/www/staging/bea/wlserver_10.3 WWW_ENV=staging WWW_ENV_ROOT=/www/staging _=/www/staging/bea/domains/mydomain4/bin/startManagedWebLogic_custom_itms.sh

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to create a summary file of all files in a directory sorted in reverse alphabetical order.?

I have an interactive script which works terrific at processing a folder of unsorted files into new directories. I am wondering how I could modify my script so that( upon execution) it provides an additional labelled summary file on my desktop that lists all of the files in each directory that... (4 Replies)
Discussion started by: Braveheart
4 Replies

2. Shell Programming and Scripting

Want to grep records in alphabetical order from a file and split into other files

Hi All, I have one file containing thousands of table names in single column. Now I want that file split into multiple files e.g one file containing table names starting from A, other containing all tables starting from B...and so on..till Z. I tried below but it did not work. for i in... (6 Replies)
Discussion started by: shekhar_4_u
6 Replies

3. AIX

List of installed applications

Hi All, I am new bee in AIX and i am trying to list out installed packages on any AIX machine in below format: packagename:<application/package name> ; <application/package version> ; <application/package vendor> can some one please suggest small script which will use lslpp and provide... (5 Replies)
Discussion started by: omkar.jadhav
5 Replies

4. Homework & Coursework Questions

Script program to count only alphabetical characters

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell script program to count the ONLY the number of alphabetic characters stored in the shell variable... (1 Reply)
Discussion started by: kofine05
1 Replies

5. Shell Programming and Scripting

Sorting lines between patterns in alphabetical order

Hi, need help in sorting lines between strings "<section status = “ole-service”>" and "</section>" in alphabetical order, based on the text in red. Hoping for an AWK or SED solution. Thank you. ... <section status = “ole-service”>... <p service = "OOO">XZZ</p> <p service = "AAA">AAA... (3 Replies)
Discussion started by: pioavi
3 Replies

6. Shell Programming and Scripting

[SHELL] Userlist alphabetical order

Hi everyone! I am new to the forum and have recently started working with Linux. Quick question, I want a user list in alphabetical order as the output of a shell script. Who can help me!? Thanks! From the netherlands ;) (5 Replies)
Discussion started by: dennisbest85
5 Replies

7. Shell Programming and Scripting

Counts a number of unique word contained in the file and print them in alphabetical order

What should be the Shell script that counts a number of unique word contained in a file and print them in alphabetical order line by line? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

8. UNIX for Dummies Questions & Answers

How can I list the file under a directory both in alphabetical and in reverse alphabetical order?

How can I list the file under current directory both in alphabetical and in reverse alphabetical order? (1 Reply)
Discussion started by: g.ashok
1 Replies

9. Shell Programming and Scripting

alphabetical order with out using sort command

hai, how can i sort a file alphabetically without using sort command (6 Replies)
Discussion started by: rahul801
6 Replies

10. Shell Programming and Scripting

shell program for sorting strings in an alphabetical order

Hi, I trying to find the solution for writing the programming in unix by shell programming for sorting thr string in alphabetical order. I getting diffculty in that ,, so i want to find out the solution for that Please do needful Thanks Bhagyesh (1 Reply)
Discussion started by: bp_vanarse
1 Replies
Login or Register to Ask a Question