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?
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
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.
That I had changed......but as currently I am not getting '-' from my ps command (that will come when there will be a erros and I will send mail in THEN condition....). I have pts/2 as TTY value....I get the following message:
pts/2: 0403-009 The specified number is not valid for this command.
I am replacing -eq with == and it gives syntax error.....can you please suggest me in the following...
if [ `ps -efo tty,time,args|awk '/test/{print $1}'` -eq '-' -a `ps -efo tty,time,args|awk '/test/{print $2}'` -ne "0:00" ]