The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Results of command execution into array alirezan Shell Programming and Scripting 2 08-18-2008 11:17 PM
Iteration through the results from a unix command deviprasad83 Shell Programming and Scripting 4 06-12-2008 04:04 AM
joining command results, and substitution ncatdesigner Shell Programming and Scripting 6 04-17-2008 11:37 AM
Setting the Results of a Command to a Variable stky13 UNIX for Dummies Questions & Answers 1 02-29-2008 03:00 PM
How to output the results of the AT command - properly! SpanishPassion UNIX for Dummies Questions & Answers 4 12-04-2005 10:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-07-2008
yale_work yale_work is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 28
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 (permalink)  
Old 10-07-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
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 (permalink)  
Old 10-07-2008
yale_work yale_work is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 28
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 (permalink)  
Old 10-07-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Quote:
Originally Posted by yale_work View Post
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 (permalink)  
Old 10-07-2008
yale_work yale_work is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 28
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 (permalink)  
Old 10-07-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Quote:
Originally Posted by yale_work View Post
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 ';'
  #7 (permalink)  
Old 10-07-2008
yale_work yale_work is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 28
Thaks I will try again.
Closed Thread

Bookmarks

Tags
filter values, ps command

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0