getting results after using ps command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting results after using ps command
# 1  
Old 10-07-2008
getting results after using ps command

Hi,

I want to use the following ps coomand:
ps -ef | grep test

Result of this command is:
Test 161220 1 0 Oct 04 - 1:11 /test/test

Just mentioning the description of each value in the result:
UID PID PPID C STIME TTY TIME CMD
Test 161220 1 0 Oct 04 - 1:11 /test/test

NOW the requirement is to check the 'TTY' value and 'TIME' value. I have to do certain operations if TTY = '-' and TIME !=0:00 ..........Please help me how to do that?

Thanks.
# 2  
Old 10-07-2008
try this
Code:
 
if [ `ps -efo tty,time,args|awk '/test/{print $1}'` -eq '-' -a `ps -efo tty,time,args|awk '/test/{print $2}'` -ne "0:00" ]

# 3  
Old 10-07-2008
Thanks Vidyadhar,

It is giving error, saying no match for if.....I tried by putting fi...did not work....also it is not any file in which I will have TIME and TTY..........Actually in my shell script I will execute "ps -ef | grep test" command first and then in the second line I want to do that operation on the result set of "ps -ef | grep test" command.

I think we should check 6th (TTY) and 7th (TIME) column values. Please suggest.
# 4  
Old 10-07-2008
Quote:
Originally Posted by yale_work
Thanks Vidyadhar,

It is giving error, saying no match for if.....I tried by putting fi...did not work....also it is not any file in which I will have TIME and TTY..........Actually in my shell script I will execute "ps -ef | grep test" command first and then in the second line I want to do that operation on the result set of "ps -ef | grep test" command.

I think we should check 6th (TTY) and 7th (TIME) column values. Please suggest.
ya i know its not file.. thats why i selected the required fields from ps -ef by using -o option it will give only TTY ,TIME and ARGS field.
did you tried if ;then;fi?? if its not working take TTY and TIME in some variables and then compare it in inside if loop..
regards,
vidyadhar
# 5  
Old 10-07-2008
I tried something like that.....
ps -ef | grep test
if [ `ps -efo tty,time,args|awk '/test/{print $1}'` -eq '-' -a `ps -efo tty,time,args|awk '/test/{print $2}'` -ne "0:00" ] then
1
fi

error message was:
0403-057 Syntax error: `fi' is not expected.
# 6  
Old 10-07-2008
Thaks I will try again.
# 7  
Old 10-07-2008
Quote:
Originally Posted by yale_work
I tried something like that.....
ps -ef | grep olapisrv
if [ `ps -efo tty,time,args|awk '/test/{print $1}'` -eq '-' -a `ps -efo tty,time,args|awk '/test/{print $2}'` -ne "0:00" ] then
1
fi

error message was:
0403-057 Syntax error: `fi' is not expected.
are you aearching for olapisrv?? then inplace of test write olapisrv and after if you need ';'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot get results from grep command

Hi, i have a file hello.log which as several line that look like the below 2015-12-07 09:46:56 0:339 120.111.12.12 POST /helloWorld 2015-12-07 09:46:57 0:439 122.111.12.12 POST /helloWorld .... when i grep expecting to see results like the below. ... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Echoing command results

Sorry folks, Second time today. I am working on a script that accepts data via pipe and processes it. I expect it to work as: # command | ProcScript.sh Within ProcScript.sh, I want to be able to give the target of the prev run command I am using history 2 | grep -v history | awk... (18 Replies)
Discussion started by: Marc G
18 Replies

3. UNIX for Dummies Questions & Answers

Acting on results from a grep command

Hi, I am currently reading a tar file and searching for a particular word using grep e.g. Plane. At the moment, if a sentence is found with the word "Plane" the sentence itself is piped to another file. Here is the code i am using; for jar in 'cat jar_file.tar'; do tar -tvf... (3 Replies)
Discussion started by: crunchie
3 Replies

4. Shell Programming and Scripting

SSH with and without command gives different results

works as expected $ ssh 172.24.40.100 Last login: Mon Jan 1 06:07:24 2001 from 172.24.41.78 # /path/script.sh gives me error consistent with env setup $ ssh 172.24.40.100 /path/script.sh Which implies the latter is running the script.sh on host a, when I want to 'launch' in from a, and... (3 Replies)
Discussion started by: IanVaughan
3 Replies

5. UNIX for Dummies Questions & Answers

df and du command showing different results

I recently encountered this on the AIX system df command showed usage is 100% i.e 1.5 GB while du command showed usage is only 500MB Why are the 2 commands showing different output This command shows usage is 1.5 GB nlxdsm29:deqadm 24> df -k . /usr/sap/DEQ ... (3 Replies)
Discussion started by: ameya_joshi
3 Replies

6. Shell Programming and Scripting

Iteration through the results from a unix command

Hi, I am using a command "ps -ef | grep identify" which results more than 1 results. Actually I need to get the time from each of them , compare with the current date and conditionally stop a process. The problem I am facing is to iterate through the results getting from the command.... (4 Replies)
Discussion started by: deviprasad83
4 Replies

7. Shell Programming and Scripting

joining command results, and substitution

Hello community I'd like to join to command results and put it to the same line in one file, how can I do that? file: a.txt so when I put Date '+%H:%M' and echo date '+%D' in the file appears 14:44 01/05/08 not 14:44 01/05/08 I like to know how can I make a substituion of a whole... (6 Replies)
Discussion started by: ncatdesigner
6 Replies

8. Shell Programming and Scripting

edit results of a find command

Hi Purpose is to have a utility command to find and edit files . I tried a function like the following in my .profile file function vifind(){ find . -name $1 -print -exec vi {} \; } Is this correct? is there a better way to do it? I see this behaving a bit strange in case of AIX, and... (6 Replies)
Discussion started by: grep_whoami
6 Replies

9. UNIX for Dummies Questions & Answers

My ps -ef|grep command results are chopped off

On our one HP-UX 11i box, we have some very long paths defined. When I want to check on our user processes running, the resulting paths are chopped off. /xyz/abc/123/......./server/b is really a process running in the ..../server/bin directory. Is this a terminal problem or buffer length... (1 Reply)
Discussion started by: bsp18974
1 Replies

10. UNIX for Dummies Questions & Answers

How to output the results of the AT command - properly!

Hi, I am new to UNIX and I am more used to simple commands like those in VMS. One of them is the ability to get the output from a job using the /out=<file> command in VMS. I want to submit a job (a set of unix commands) using the AT command but to get the output in a file like that used in... (4 Replies)
Discussion started by: SpanishPassion
4 Replies
Login or Register to Ask a Question