Serching process names


 
Thread Tools Search this Thread
Top Forums Programming Serching process names
# 1  
Old 10-18-2011
Serching process names

Code:
#include <stdio.h>
#include <string.h>

int main(void)
{
        char buf[16384];

        int transcount=0, elapsetotal=0;

        while(!feof(stdin))
        {
                int newoluf=0, elapsetime=-1;
                char timestamp[64]={0};

                buf[0]='\0';        // Blank out buffer

                while(strcmp(buf, "BEGINTRANS\n") != 0)        // look for BEGINTRANS
                if(fgets(buf, 16384, stdin) == NULL)
                        break;        // EOF

                if(feof(stdin)) break;

                while(strcmp(buf, "ENDTRANS\n") != 0)        // Look for ENDTRANS
                {
                        const char *tsstr;
                        if(fgets(buf, 16384, stdin) == NULL)
                                break;

                        if(strstr(buf, "NEWOLUF2") != NULL)
                                newoluf=1;

                        if(tsstr=strstr(buf, "Timestamp"))
                                sscanf(tsstr, "Timestamp <%[^>]>", timestamp);

                        if(strncmp(buf, "ElapseTime", 10) == 0)
                                sscanf(buf, "ElapseTime <%d>", &elapsetime);
                }

                if((elapsetime>=0) && (timestamp[0]))
                {
                        transcount++;
                        elapsetotal += elapsetime;
                        printf("trans %d, elapsetime %d, timestamp %s\n",
                                transcount, elapsetime, timestamp);
                }
        }

        printf("Average elapsetime is %d\n", elapsetotal / transcount);
        return(0);
}

This is the code i got from this site but i want to search for more than one keyword in the some file almost has same content how do i get the process names and corresponding parameter values in my file please help in finding the problem.

Last edited by jim mcnamara; 10-18-2011 at 08:52 AM.. Reason: code tags
# 2  
Old 10-18-2011
Use [code] tags please!!!

What do you mean "process names". Are these coming from the input? If so, what does the input look like?
# 3  
Old 10-19-2011
The input is a file which consists of the process names between two strings start and end, i have to retrieve the content between these two strings and get the output the file will look like as follows..


START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-37> Input <NEWOLUF2!NEWOLUF2<?xml version="1.0" standalone="yes
"?><OLUF2><INPUT><FLT>SK 1467</FLT><LEG>OSLCPH</LEG><DEPDATE>27SEP11</DEPDATE><BUCKET>Y</BUCKET><BUCKETBKGCL>Y</BUCKETBKGCL><B
KGCL>Y</BKGCL><PARMS>Y</PARMS><COMMENTS>Y</COMMENTS><WARNINGS>Y</WARNINGS><OPARAMETERS>Y</OPARAMETERS><LOCALAVAPOS>Y</LOCALAVA
POS></INPUT></OLUF2>>
ElapseTime <745> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-37> Input <NEWOLUF2!NEWOLUF2<?xml version="1.0" standalone="yes
"?><OLUF2><INPUT><FLT>SK 1455</FLT><LEG>OSLCPH</LEG><DEPDATE>29SEP11</DEPDATE><BUCKET>Y</BUCKET><BUCKETBKGCL>Y</BUCKETBKGCL><B
KGCL>Y</BKGCL><PARMS>Y</PARMS><COMMENTS>Y</COMMENTS><WARNINGS>Y</WARNINGS><OPARAMETERS>Y</OPARAMETERS><LOCALAVAPOS>Y</LOCALAVA
POS></INPUT></OLUF2>>
ElapseTime <765> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-37> Input <<NAVSREQUEST><FLT>SK 4417 </FLT><LEG>TOSOSL</LEG><DE
PDATE>02SEP12</DEPDATE></NAVSREQUEST>>
ElapseTime <579> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-38> Input <<NAVSREQUEST><FLT>SK 1467 </FLT><LEG>OSLCPH</LEG><DE
PDATE>27SEP11</DEPDATE></NAVSREQUEST>>
ElapseTime <356> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-38> Input <<NAVSREQUEST><FLT>SK 1455 </FLT><LEG>OSLCPH</LEG><DE
PDATE>29SEP11</DEPDATE></NAVSREQUEST>>
ElapseTime <390> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-41> Input <DEPLEGS!1!CMD=0#STAT=0#MAXREC= 8#FLT=SK 1467 #DEPDAT
E=18SEP11>
ElapseTime <286> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-41> Input <NEWOLUF2!NEWOLUF2<?xml version="1.0" standalone="yes
"?><OLUF2><INPUT><FLT>SK 1467</FLT><LEG>OSLCPH</LEG><DEPDATE>18SEP11</DEPDATE><BUCKET>Y</BUCKET><BUCKETBKGCL>Y</BUCKETBKGCL><B
KGCL>Y</BKGCL><PARMS>Y</PARMS><COMMENTS>Y</COMMENTS><WARNINGS>Y</WARNINGS><OPARAMETERS>Y</OPARAMETERS><LOCALAVAPOS>Y</LOCALAVA
POS></INPUT></OLUF2>>
ElapseTime <651> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-42> Input <<NAVSREQUEST><FLT>SK 1467 </FLT><LEG>OSLCPH</LEG><DE
PDATE>18SEP11</DEPDATE></NAVSREQUEST>>
ElapseTime <292> milliseconds
END
START
logging.c/LogTransactionInput (3105) : Timestamp <14Sep1111-07-52> Input <DEPLEGS!1!CMD=0#STAT=0#MAXREC= 8#FLT=SK 0811 #DEPDAT
E=02SEP12>
ElapseTime <345> milliseconds
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

3. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

4. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

5. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

6. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

7. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

8. Shell Programming and Scripting

eleminate repated process names and get second column value

i want shell script who can eliminate those repeated process and get value of top process of second column. Mark with red one only i want other repeated process should be eliminate but how? Help me out guys. oracle 496094 oracle 471572 oracle 471497 oracle 470561 ko9coll 96157... (4 Replies)
Discussion started by: siddiqui
4 Replies

9. UNIX for Dummies Questions & Answers

Process id's in file names

Hello, I am editing a script which has a .sh extension but is listed as #! /bin/ksh that has output files where process ID's are somehow getting tacked onto the end of the filename. The programmer codes these scripts as "/tmp/email_file$$" saying that he put the $$ in there to be able to handle... (1 Reply)
Discussion started by: tekster757
1 Replies

10. UNIX for Dummies Questions & Answers

Displaying VERY long process names with ps -ef

Hi, I'm trying to display all process on an AIX server with the string SLRServer in them. Normally "ps -ef|grep SLRServer" would be sufficient, however in this instance the process name is enormous and the part which contains this string has been truncated, as you can see in the example below ... (8 Replies)
Discussion started by: m223464
8 Replies
Login or Register to Ask a Question